結果

問題 No.2206 Popcount Sum 2
ユーザー i_am_noob
提出日時 2023-02-12 17:03:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 616 ms / 4,000 ms
コード長 1,865 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 204,188 KB
最終ジャッジ日時 2025-02-10 14:49:00
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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";
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0