結果
問題 |
No.2206 Popcount Sum 2
|
ユーザー |
![]() |
提出日時 | 2025-08-02 20:17:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,018 bytes |
コンパイル時間 | 3,630 ms |
コンパイル使用メモリ | 281,340 KB |
実行使用メモリ | 9,088 KB |
最終ジャッジ日時 | 2025-08-02 20:17:13 |
合計ジャッジ時間 | 11,000 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 WA * 7 |
ソースコード
#include <bits/stdc++.h> #define lzm0107 using namespace std; using ll = long long; using aii = array<int, 2>; using cd = complex<double>; using ull = unsigned long long; const int Q = 2e5, N = 2e5, P = 998244353, B = 447, INV_2 = 499122177; int fact[N + 10], finv[N + 10]; int pow2[N + 10]; int q; array<int, 3> qry[Q + 10]; int ans[Q + 10]; int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = static_cast<ll>(a) * a % P) { if (b & 1) { res = static_cast<ll>(res) * a % P; } } return res; } int C(int a, int b) { return static_cast<ll>(fact[a]) * finv[b] % P * finv[a - b] % P; } void inc(int &a, int b) { if ((a += b) - P >= 0) { a -= P; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); fact[0] = 1; for (int i = 1; i <= N; ++i) { fact[i] = static_cast<ll>(fact[i - 1]) * i % P; } finv[N] = qpow(fact[N], P - 2); for (int i = N - 1; i >= 0; --i) { finv[i] = static_cast<ll>(finv[i + 1]) * (i + 1) % P; } pow2[0] = 1; for (int i = 1; i <= N; ++i) { if ((pow2[i] = pow2[i - 1] << 1) - P >= 0) { pow2[i] -= P; } } cin >> q; for (int i = 1; i <= q; ++i) { cin >> qry[i][0] >> qry[i][1]; --qry[i][0]; --qry[i][1]; qry[i][2] = i; } sort(qry + 1, qry + q + 1, [](auto lhs, auto rhs) -> bool { if (lhs[0] / B != rhs[0] / B) { return lhs[0] < rhs[0]; } else if (lhs[0] / B & 1) { return lhs[1] > rhs[1]; } else { return lhs[1] < rhs[1]; } }); int n = 0, m = 0, res = 1; for (int i = 1; i <= q; ++i) { while (n < qry[i][0]) { if ((res <<= 1) - P >= 0) { res -= P; } inc(res, P - C(n, m)); ++n; } while (m < qry[i][1]) { ++m; inc(res, C(n, m)); } while (n > qry[i][0]) { --n; inc(res, C(n, m)); res = static_cast<ll>(INV_2) * res % P; } while (m > qry[i][1]) { inc(res, P - C(n, m)); --m; } int tmp = pow2[qry[i][0] + 1]; inc(tmp, P - 1); ans[qry[i][2]] = static_cast<ll>(res) * tmp % P; } for (int i = 1; i <= q; ++i) { cout << ans[i] << '\n'; } return 0; }