Twice_Greater.cpp

Anonymous
c_cpp
02/26/2026 3:18 AM
1.1 KB
50
Indexable
#include <bits/stdc++.h>
using namespace std;

// Time Complexity: O(n log n)
// Space Complexity: O(n)

using ll = long long;

const ll m = 998244353;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);

	const int NMX = 3*1e5;
	vector<ll> pow2(NMX); pow2[0] = 1;
	for(int i = 1; i < NMX; i++) pow2[i] = (pow2[i-1]*2)%m;

	int tc; cin >> tc;
	while(tc--) {
		int n; cin >> n;
		vector<ll> a(n);
		for(auto &x : a) cin >> x;

		vector<vector<ll>> dp(n, vector<ll>(32, 0));
		vector<ll> psum_k(32, 0); psum_k[0] = 1; int k = n;
		ll ans = 0;
		for(int i = n-1; i >= 0; i--) {
			while(a[k-1] > 2*a[i]) {
				k--;
				for(int j = 0; j < 32; j++) psum_k[j] += dp[k][j], psum_k[j] %= m;
			}
			for(int j = 1; j < 32; j++) {
				dp[i][j] = (psum_k[j-1]*pow2[k-i-1])%m;
				ans += (dp[i][j]*j)%m, ans %= m;
			}
		}
		cout << ans << "\n";
	}

	return 0;
}
Editor is loading...
Leave a Comment