結果
| 問題 | No.2206 Popcount Sum 2 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-08-05 22:54:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 694 ms / 4,000 ms |
| コード長 | 2,116 bytes |
| 記録 | |
| コンパイル時間 | 1,636 ms |
| コンパイル使用メモリ | 169,680 KB |
| 実行使用メモリ | 13,076 KB |
| 最終ジャッジ日時 | 2025-08-05 22:54:59 |
| 合計ジャッジ時間 | 10,370 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using ull = uint64_t;
using u16 = uint16_t;
using u32 = uint32_t;
using ldb = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using puu = pair<ull, ull>;
#define fi first
#define se second
#define ep emplace
#define mp make_pair
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define ffor(x, l, r) for (int x = (l); x <= (r); x++)
#define rfor(x, r, l) for (int x = (r); x >= (l); x--)
// #define int long long
typedef array<ll, 3> ar3;
random_device rd;
mt19937 rng(rd());
constexpr int N = 2e5 + 100;
constexpr int B = 450;
constexpr int mod = 998244353;
ll fac[N], ifac[N];
ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
b >>= 1, a = a * a % mod;
}
return res;
}
void init(int n) {
fac[0] = 1;
ffor(i, 1, n) fac[i] = fac[i - 1] * i % mod;
ifac[n] = qpow(fac[n], mod - 2);
rfor(i, n - 1, 0) ifac[i] = ifac[i + 1] * (i + 1) % mod;
}
ll C(ll n, ll m) {
if (n < m)
return 0;
else
return fac[n] * ifac[n - m] % mod * ifac[m] % mod;
}
ar3 q[N];
int n = 2e5, bel[N], res[N];
signed main() {
init(2e5);
cin.tie(0)->sync_with_stdio(0);
int T;
cin >> T;
ffor(i, 1, T) q[i][0] = i, cin >> q[i][2] >> q[i][1];
ffor(i, 1, T) q[i][1]--, q[i][2]--;
int cur = 1;
ffor(i, 1, n) bel[i] = (cur += cur * B < i);
bel[0] = 1;
auto cmp = [&](ar3 x, ar3 y) {
return bel[x[1]] ^ bel[y[1]] ? bel[x[1]] < bel[y[1]] : (bel[x[1]] & 1 ? x[2] < y[2] : x[2] > y[2]);
};
sort(q + 1, q + T + 1, cmp);
ll ans = 1;
int l = 0, r = 1;
const int inv2 = qpow(2, mod - 2);
ffor(i, 1, T) {
int ql = q[i][1], qr = q[i][2];
while (r < qr) ans = (ans * 2 % mod - C(r++, l)) % mod;
while (l < ql) ans = (ans + C(r, ++l)) % mod;
while (l > ql) ans = (ans - C(r, l--)) % mod;
while (r > qr) ans = (ans + C(--r, l)) % mod * inv2 % mod;
// cerr << ql << ' ' << qr << ' ' << ans << '\n';
res[q[i][0]] = ans * (qpow(2, qr + 1) % mod - 1) % mod;
}
ffor(i, 1, T) cout << (res[i] + mod) % mod << '\n';
return 0;
}
vjudge1