結果
| 問題 |
No.2206 Popcount Sum 2
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-08-14 17:11:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,548 bytes |
| コンパイル時間 | 1,992 ms |
| コンパイル使用メモリ | 197,684 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2025-08-14 17:11:51 |
| 合計ジャッジ時間 | 11,916 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int kMaxN = 2e5 + 5, kM = 998244353, kInV = (kM + 1) / 2;
struct A {
int l, r, p, id;
bool operator<(const A &a) const {
return p == a.p ? r < a.r : l < a.l;
}
} a[kMaxN];
int ans[kMaxN], n;
LL p[kMaxN], inv[kMaxN];
LL P(LL x, LL y) {
LL ans = 1;
for (LL i = 1; i <= y; i <<= 1, x = x * x % kM) {
(y & i) && (ans = ans * x % kM);
}
return ans;
}
LL C(LL x, LL y) {
if (x < y || x < 0 || y < 0) {
return 0;
} else {
return p[x] * inv[y] % kM * inv[x - y] % kM;
}
}
int main() {
ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
p[0] = inv[0] = 1;
for (int i = 1; i < kMaxN; i++) {
p[i] = p[i - 1] * i % kM;
inv[i] = P(p[i], kM - 2);
}
cin >> n;
int d = sqrt(n);
for (int i = 1; i <= n; i++) {
cin >> a[i].l >> a[i].r;
a[i].l--, a[i].r--;
a[i].p = a[i].l / d + bool(a[i].l % d), a[i].id = i;
}
sort(a + 1, a + n + 1);
LL s = 0;
for (int i = 0; i <= a[i].r; i++) {
s = (s + C(a[i].l, i)) % kM;
}
ans[a[1].id] = s;
int x = a[1].l, y = a[1].r;
for (int i = 2; i <= n; i++) {
for (; y < a[i].r; y++, s = (s + C(x, y)) % kM) {
}
for (; y > a[i].r; s = (s - C(x, y) + kM) % kM, y--) {
}
for (; x < a[i].l; s = (s * 2 - C(x, y) + kM) % kM, x++) {
}
for (; x > a[i].l; x--, s = (s + C(x, y)) % kM * kInV % kM) {
}
ans[a[i].id] = s;
}
for (int i = 1; i <= n; i++) {
cout << ans[i] * (P(2, a[i].l + 1) - 1 + kM) % kM << "\n";
}
return 0;
}
vjudge1