結果
問題 |
No.2206 Popcount Sum 2
|
ユーザー |
![]() |
提出日時 | 2025-08-02 16:10:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,399 bytes |
コンパイル時間 | 1,624 ms |
コンパイル使用メモリ | 167,784 KB |
実行使用メモリ | 14,624 KB |
最終ジャッジ日時 | 2025-08-02 16:10:24 |
合計ジャッジ時間 | 9,591 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define MAXN 200005 #define bl(x) (((x)-1)/B+1) const int MOD(998244353); const int inv2(499122177); int t, B, res(1); int fac[MAXN], ifac[MAXN], pw[MAXN], ans[MAXN]; struct Que{int l, r, id;}que[MAXN]; int qpow(int x, int k=MOD-2){int res(1); for (; k; k>>=1, (x*=x)%=MOD) if (k&1) (res*=x)%=MOD; return res;} int C(int n, int m){return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;} signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); fac[0] = ifac[0] = pw[0] = 1; for (int i(1); i<MAXN; ++i) pw[i] = (pw[i-1]*2)%MOD, ifac[i] = qpow(fac[i]=i*fac[i-1]%MOD); cin >> t; for (int i(1); i<=t; ++i) cin >> que[i].r >> que[i].l, ans[que[i].id=i] = (pw[que[i].r]-1+MOD)%MOD; B = MAXN/sqrt(t); // cerr << bl(que[1].l) << ' ' << bl(que[2].l) << '\n'; sort(que+1, que+t+1, [](Que a, Que b){return bl(a.l) == bl(b.l) ? (bl(a.l) & 1 ? a.r < b.r : a.r > b.r) : bl(a.l) < bl(b.l);}); for (int i(1), l(1), r(1); i<=t; ++i){ while (l > que[i].l) (res += MOD-C(r-1, --l)) %= MOD; while (r < que[i].r) (res += res+MOD-C(r++, l-1)) %= MOD; // cerr << res << '\n'; while (l < que[i].l) (res += C(r-1, l++)) %= MOD; while (r > que[i].r) res = (res+C((--r)-1, l-1))*inv2%MOD; (ans[que[i].id] *= res) %= MOD; } for (int i(1); i<=t; ++i) cout << ans[i] << '\n'; return 0; }