結果
| 問題 | No.2206 Popcount Sum 2 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-08-02 19:59:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 626 ms / 4,000 ms |
| コード長 | 1,423 bytes |
| 記録 | |
| コンパイル時間 | 1,835 ms |
| コンパイル使用メモリ | 169,236 KB |
| 実行使用メモリ | 12,240 KB |
| 最終ジャッジ日時 | 2025-08-02 19:59:26 |
| 合計ジャッジ時間 | 10,877 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int kMaxN = 2e5 + 1, mod = 998244353, B = 447;
int t, n[kMaxN], o, p, l, r, a[kMaxN];
ll s;
array<int, 3> q[kMaxN];
ll j[kMaxN], y[kMaxN], e[kMaxN];
ll C(int n, int m) {
return j[n] * y[m] % mod * y[n - m] % mod;
}
ll P(ll a, int b, ll ans = 1) {
for (int i = 1; i <= b; i <<= 1, a = a * a % mod) {
(i & b) && (ans = ans * a % mod);
}
return ans;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> t, j[0] = y[0] = e[0] = 1;
for (int i = 1; i < kMaxN; i++) {
j[i] = j[i - 1] * i % mod, y[i] = P(j[i], mod - 2), e[i] = e[i - 1] * 2 % mod;
}
for (int i = 1; i <= t; i++) {
cin >> n[i], cin >> q[i][0], q[i][0]--, q[i][1] = n[i] - 1, q[i][2] = i;
}
sort(q + 1, q + t + 1, [](array<int, 3> x, array<int, 3> y) { return ((o = x[0] / B) == (p = y[0] / B) ? (o % 2 ? x[1] < y[1] : x[1] > y[1]) : o < p); });
l = 0, r = q[1][1], s = 1;
for (int i = 1; i <= t; i++) {
for (; q[i][0] < l; s = s + mod - C(r, l), l--, s >= mod && (s -= mod)) {
}
for (; r < q[i][1]; s = (2 * s + mod - C(r, l)) % mod, r++) {
}
for (; q[i][0] > l; l++, s = (s + C(r, l)) % mod, s >= mod && (s -= mod)) {
}
for (; r > q[i][1]; r--, s = (s + C(r, l)) * 499122177 % mod) {
}
a[q[i][2]] = s;
}
for (int i = 1; i <= t; i++) {
cout << (e[n[i]] - 1) * a[i] % mod << '\n';
}
return 0;
}
vjudge1