結果

問題 No.2206 Popcount Sum 2
コンテスト
ユーザー vjudge1
提出日時 2026-05-14 16:58:18
言語 C++17(gnu拡張)
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 2,082 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,528 ms
コンパイル使用メモリ 220,348 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2026-05-14 16:58:57
合計ジャッジ時間 10,777 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 TLE * 1 -- * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void init(i64)':
main.cpp:29:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   29 |         rep (i, 1, n) fac[i] = fac[i - 1] * i % mod, ifac[i] = qpow(fac[i], mod - 2), sc[i] = sc[i - 1] + qpow(2, i), sc[i] %= mod;
      |              ^
main.cpp:3:40: note: in definition of macro 'rep'
    3 | #define rep(i, j, k) for (register int i = j; i <= k; ++i)
      |                                        ^
main.cpp: At global scope:
main.cpp:49:8: warning: first argument of 'int main(i64, char**)' should be 'int' [-Wmain]
   49 | signed main(int argc, char* argv[]) {
      |        ^~~~
main.cpp: In function 'int main(i64, char**)':
main.cpp:59:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   59 |         rep (i, 1, q) {
      |              ^
main.cpp:3:40: note: in definition of macro 'rep'
    3 | #define rep(i, j, k) for (register int i = j; i <= k; ++i)
      |                                        ^
main.cpp:75:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   75 |         rep (i, 1, q) cout << ans[i] << '\n';
      |              ^
main.cpp:3:40: note: in definition of macro 'rep'
    3 | #define rep(i, j, k) for (register int i = j; i <= k; ++i)
      |                                        ^

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (register int i = j; i <= k; ++i)
#define per(i, j, k) for (register int i = j; i >= k; --i)
#define sz(x) (int)x.size()
const long long mod = 998244353;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using pii = pair<int, int>;
using pll = pair<i64, i64>;
#define int i64
mt19937_64 rng((u64)random_device {}() << 32 ^ random_device {}() ^ chrono::high_resolution_clock::now().time_since_epoch().count());
template<class T = i64,class T2>T rnd(T l,T2 r) {
	return uniform_int_distribution<T>(l,r)(rng);
}

const int N = 4e5 + 10;

i64 fac[N], ifac[N], sc[N];

i64 qpow(i64 a, int b, i64 res = 1) {
	for (; b > 0; b >>= 1, a = a * a % mod) if (b & 1) res = res * a % mod;
	return res;
}

void init(int n = 4e5) {
	fac[0] = ifac[0] = sc[0] = 1;
	rep (i, 1, n) fac[i] = fac[i - 1] * i % mod, ifac[i] = qpow(fac[i], mod - 2), sc[i] = sc[i - 1] + qpow(2, i), sc[i] %= mod;
}

i64 comb(int n, int k) {
	if (k > n || n < 0 || k < 0) return 0;
	return fac[n] * ifac[k] % mod * ifac[n - k] % mod;
}
array<int, 3> s[N];
int ans[N], col[N];
int n, B;
bool cmp(array<int, 3> x, array<int, 3> y) {
	if (x[0] / B != y[0] / B) return x[0] / B < y[0] / B;
	return x[1] < y[1];
}

int norm(int p) {
	p = (p % mod + mod) % mod;
	return p;
}

signed main(int argc, char* argv[]) {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	init();
	int q;
	cin >> q;
	B = sqrt(q);
	rep (i, 1, q) {
		int x, y;
		cin >> x >> y;
		s[i] = {y - 1, x - 1, i};
	}
	sort(s + 1, s + n + 1);
	int inv = qpow(2, mod - 2);
	for (int i = 1, l = 0, r = 1, res = 1; i <= q; ++i) {
		int x = s[i][0], y = s[i][1];
		//	cout << x << ' ' << y << '\n';
		while (l > x) res = norm(res - comb(r, l)), l--;
		while (l < x) l++, res = norm(res + comb(r, l));
		while (r > y) r--, res = (res + comb(r, l)) % mod * inv % mod;
		while (r < y) res = norm(res * 2 - comb(r, l)), r++;
		ans[s[i][2]] = res * sc[y] % mod;
	}
	rep (i, 1, q) cout << ans[i] << '\n';
}
0