版本比较
CF2157 几句话题解
正文
增加 86 行删除 0 行
29 行未改动3031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811929 行未改动
### CF2157F
有类 BIT 式逐位更新的写法也有多层分块的写法,主播赛时写的后者,更好想。具体就是利用分块减小需要增大 x 的次数,把所有位置一个一个往后提溜到想要的位置,小块处理完之后大块用同样的办法,最后最外层的分块直接暴力往后提即可。本质交互题,CF最近越来越喜欢出了。
```#include<bits/stdc++.h>using namespace std;
// --- Types ---using ll=long long;using db=double;using pii=pair<int,int>;using pll=pair<ll,ll>;using vi=vector<int>;using vl=vector<ll>;using poly=vi;
// --- Macros ---#define fi first#define se second#define endl '\n'#define vec vector#define pb push_back#define eb emplace_back#define sz(x) ((ll)(x).size())#define bg begin()#define ed end()#define all(x) (x).begin(),(x).end()#define All(x) (x).begin()+1,(x).end()#define rall(x) (x).rbegin(),(x).rend()#define unq(v) (v).erase(unique(all(v)),(v).end())
// --- Loops ---#define rep(i,a,b) for(ll i=(a);i<=(b);++i)#define per(i,a,b) for(ll i=(a);i>=(b);--i)#define fore(x,a) for(auto& x:a)
// --- Utils ---template<class T> bool chmin(T& a,const T& b) { return b<a?a=b,1:0; }template<class T> bool chmax(T& a,const T& b) { return a<b?a=b,1:0; }
const ll MOD=998244353;
struct Nd{ ll cnt=0,sx=0,sy=0,sxy=0;};
void add(ll& x,ll y){ x+=y; if(x>=MOD)x%=MOD; }
void solve(){ unsigned long long n,d; cin>>n>>d; Nd dp[2][2],np[2][2]; dp[0][0].cnt=1; rep(k,0,59){ rep(c,0,1) rep(b,0,1) np[c][b]=Nd(); ll nk=(n>>k)&1,dk=(d>>k)&1; rep(c,0,1) rep(b,0,1){ Nd cur=dp[c][b]; rep(x,0,1){ ll s=x+dk+c; ll y=s&1; ll nc=s>>1; ll nb=(nk-b-x<0); Nd& to=np[nc][nb]; add(to.cnt,cur.cnt); add(to.sx,cur.sx+cur.cnt*x); add(to.sy,cur.sy+cur.cnt*y); add(to.sxy,cur.sxy+cur.sy*x+cur.sx*y+cur.cnt*x*y); } } rep(c,0,1) rep(b,0,1) dp[c][b]=np[c][b]; } ll ans=0; rep(c,0,1){ add(ans,dp[c][0].sxy); if(c) add(ans,dp[c][0].sx); } cout<<ans%MOD<<endl;}
ll T=1;signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>T; while(T--) solve(); return 0;}```