結果
問題 | No.2206 Popcount Sum 2 |
ユーザー | i_am_noob |
提出日時 | 2023-02-12 17:03:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 668 ms / 4,000 ms |
コード長 | 1,865 bytes |
コンパイル時間 | 2,492 ms |
コンパイル使用メモリ | 207,400 KB |
実行使用メモリ | 11,232 KB |
最終ジャッジ日時 | 2023-09-23 06:01:13 |
合計ジャッジ時間 | 12,900 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
5,696 KB |
testcase_01 | AC | 7 ms
5,732 KB |
testcase_02 | AC | 213 ms
5,760 KB |
testcase_03 | AC | 224 ms
5,772 KB |
testcase_04 | AC | 224 ms
5,792 KB |
testcase_05 | AC | 665 ms
10,652 KB |
testcase_06 | AC | 668 ms
11,116 KB |
testcase_07 | AC | 661 ms
10,408 KB |
testcase_08 | AC | 666 ms
10,892 KB |
testcase_09 | AC | 663 ms
10,752 KB |
testcase_10 | AC | 220 ms
10,968 KB |
testcase_11 | AC | 219 ms
10,396 KB |
testcase_12 | AC | 213 ms
11,232 KB |
testcase_13 | AC | 167 ms
10,860 KB |
testcase_14 | AC | 164 ms
10,420 KB |
testcase_15 | AC | 166 ms
10,396 KB |
testcase_16 | AC | 141 ms
10,456 KB |
testcase_17 | AC | 142 ms
10,468 KB |
testcase_18 | AC | 142 ms
10,620 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; using pii=pair<int,int>; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) const int maxn=200005,mod=998244353,C=256; int add(int x, int y){x+=y; if(x>=mod) x-=mod; return x;} int sub(int x, int y){x-=y; if(x<0) x+=mod; return x;} int mul(int x, int y){return ((ll)x)*y%mod;} int fac[maxn],ifac[maxn],pw2[maxn]; int c(int n, int m){return mul(fac[n],mul(ifac[m],ifac[n-m]));} struct MoSolver { struct query { int l, r, id; bool operator < (const query &o) { if (l / C == o.l / C) return (l / C) & 1 ? r > o.r : r < o.r; return l / C < o.l / C; } }; int cur_ans,pl,pr; vector <int> ans; vector <query> Q; void add_query(int l, int r, int id) { // [l, r) Q.push_back({l, r, id}); ans.push_back(0); } void run() { sort(Q.begin(), Q.end()); pl = 0, pr = 0; cur_ans = 1; for (query &i : Q) { while (pl > i.l) cur_ans=sub(cur_ans,c(pr,pl)),--pl; while (pr < i.r) cur_ans=sub(mul(cur_ans,2),c(pr,pl)),pr++; while (pl < i.l) cur_ans=add(cur_ans,c(pr,pl+1)),pl++; while (pr > i.r) cur_ans=mul(add(cur_ans,c(--pr,pl)),(mod+1)/2); ans[i.id] = cur_ans; } } }de; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); fac[0]=ifac[0]=ifac[1]=1; for(int i=1; i<maxn; ++i) fac[i]=mul(fac[i-1],i); for(int i=2; i<maxn; ++i) ifac[i]=mul(ifac[mod%i],mod-mod/i); for(int i=2; i<maxn; ++i) ifac[i]=mul(ifac[i],ifac[i-1]); pw2[0]=1; for(int i=1; i<maxn; ++i) pw2[i]=mul(pw2[i-1],2); int q; cin >> q; vector<int> vec; for(int i=0; i<q; ++i){ int n,m; cin >> n >> m; vec.pb(n); de.add_query(m-1,n-1,i); } de.run(); for(int i=0; i<q; ++i) cout << mul(de.ans[i],pw2[vec[i]]-1) << "\n"; }