結果
| 問題 | No.2206 Popcount Sum 2 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-07-16 21:53:05 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 625 ms / 4,000 ms |
| + 838µs | |
| コード長 | 1,370 bytes |
| 記録 | |
| コンパイル時間 | 1,075 ms |
| コンパイル使用メモリ | 187,124 KB |
| 実行使用メモリ | 14,720 KB |
| 最終ジャッジ日時 | 2026-07-16 21:53:18 |
| 合計ジャッジ時間 | 11,406 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e5 + 5, mod = 998244353;
LL t, ans[N], qwq[N][2], d;
struct zs {
LL n, m, k, i;
} a[N];
bool cmp (zs &x, zs &y) {
if (x.k == y.k) return x.m < y.m;
return x.k < y.k;
}
LL qpow (LL x, LL y) {
LL ret = 1;
for (; y; y >>= 1) {
if (y & 1) {
(ret *= x) %= mod;
}
(x *= x) %= mod;
}
return ret;
}
LL C (LL x, LL y) {
return qwq[x][0] * qwq[y][1] % mod * qwq[x - y][1] % mod;
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
qwq[0][0] = qwq[0][1] = 1;
for (int i = 1; i <= 2e5; i++) {
qwq[i][0] = qwq[i - 1][0] * i % mod;
qwq[i][1] = qpow(qwq[i][0], mod - 2);
}
cin >> t;
d = sqrt(t);
for (int i = 1; i <= t; i++) {
cin >> a[i].n >> a[i].m;
a[i].i = i; a[i].n--, a[i].m--;
a[i].k = a[i].n / d;
}
sort(a + 1, a + t + 1, cmp);
ans[0] = 1;
for (int i = 1, n = 0, m = 0; i <= t; i++) {
for (; n < a[i].n; ans[0] = (ans[0] * 2 % mod - C(n++, m) + mod) % mod);
for (; m > a[i].m; ans[0] = (ans[0] - C(n, m--) + mod) % mod);
for (; m < a[i].m; ans[0] = (ans[0] + C(n, ++m)) % mod);
for (; n > a[i].n; ans[0] = (ans[0] + C(--n, m)) % mod * qwq[2][1] % mod);
ans[a[i].i] = ans[0] * (qpow(2, a[i].n + 1) - 1) % mod;
}
for (int i = 1; i <= t; i++) {
cout << ans[i] << '\n';
}
return 0;
}
vjudge1