結果
問題 |
No.2206 Popcount Sum 2
|
ユーザー |
![]() |
提出日時 | 2025-08-02 15:33:56 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 691 ms / 4,000 ms |
コード長 | 1,602 bytes |
コンパイル時間 | 3,618 ms |
コンパイル使用メモリ | 283,380 KB |
実行使用メモリ | 13,208 KB |
最終ジャッジ日時 | 2025-08-02 15:34:10 |
合計ジャッジ時間 | 12,898 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; inline long long read(){ long long x=0; char ch; bool f=0; while(((ch=getchar())<'0'||ch>'9')&&ch!='-') ; if(ch=='-') f=1; else x=ch^48; while((ch=getchar())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48); return f?-x:x; } #define ll long long const int N=2e5+5,mod=998244353,B=447; const ll inv2=(mod+1)/2; ll jc[2][N],pw[N],ans[N]; int bl[N]; void re(){ jc[0][0]=jc[0][1]=jc[1][0]=jc[1][1]=1; for(int i=2;i<N;i++) jc[0][i]=i*jc[0][i-1]%mod,jc[1][i]=(mod-mod/i)*jc[1][mod%i]%mod; for(int i=2;i<N;i++) jc[1][i]=jc[1][i]*jc[1][i-1]%mod; pw[0]=1; for(int i=1;i<N;i++) pw[i]=pw[i-1]*2%mod; } ll C(int n,int m){ if(n<m||n<0||m<0) return 0; return jc[0][n]*jc[1][m]%mod*jc[1][n-m]%mod; } int q; struct node{ int n,m,id; bool operator<(const node &t)const{ if(bl[n]^bl[t.n]) return n<t.n; return m<t.m; } }s[N]; ll S=1; int l=0,r=0; bool cmp(node t1,node t2){ return t1.id<t2.id; } int main(){ // freopen("t1.in","r",stdin); re(); q=read(); for(int i=1;i<=q;i++){ s[i].n=read()-1,s[i].m=read()-1,s[i].id=i; } for(int i=1;i<=2e5;i++) bl[i]=(i-1)/B+1; sort(s+1,s+1+q); int l=0,r=0; for(int i=1;i<=q;i++){ while(r<s[i].m){ r++; S=S+C(l,r),S%=mod; } while(r>s[i].m){ S=S-C(l,r); S%=mod; r--; } while(l<s[i].n){ S=S*2-C(l,r),S%=mod; l++; } while(l>s[i].n){ l--; S=S+C(l,r),S=S*inv2%mod; } // cerr<<s[i].n<<","<<s[i].m<<": "<<S<<"??\n"; ans[s[i].id]=S; } sort(s+1,s+1+q,cmp); for(int i=1;i<=q;i++){ ll su=ans[i]*(pw[s[i].n+1]-1)%mod; printf("%lld\n",(su%mod+mod)%mod); } return 0; } /* mo dui */