标签:== ranking highlight change while %s char mic scanf
板子题
用的整体二分
唯一要注意的是别总手误打错变量
最近总犯这样sb错误,我佛了
#include<bits/stdc++.h> using namespace std; const int N=1e5+7; const int inf=0x3f3f3f3f; struct node{ int op,x,y,z; }q[3*N],lq[3*N],rq[3*N]; int n,m,t,a[N],c[N],ans[N],num; void change(int x,int y){ while(x<=n){ c[x]+=y; x+=x&-x; } } int ask(int x){ int y=0; while(x){ y+=c[x]; x-=x&-x; } return y; } void solve(int l,int r,int st,int ed){ if(st>ed)return; if(l==r){ for(int i=st;i<=ed;i++) if(q[i].op>0)ans[q[i].op]=l; return; } int mid=(l+r)>>1; int lt=0,rt=0; for(int i=st;i<=ed;i++){ if(q[i].op<1){ if(q[i].z<=mid)change(q[i].x,q[i].y),lq[++lt]=q[i]; else rq[++rt]=q[i]; } else { int cnt=ask(q[i].y)-ask(q[i].x-1); if(cnt>=q[i].z)lq[++lt]=q[i]; else q[i].z-=cnt,rq[++rt]=q[i]; } } for(int i=ed;i>=st;--i){ if(q[i].op<1&&q[i].z<=mid)change(q[i].x,-q[i].y); } for(int i=1;i<=lt;i++)q[st+i-1]=lq[i]; for(int i=1;i<=rt;i++)q[st+lt+i-1]=rq[i]; solve(l,mid,st,st+lt-1); solve(mid+1,r,st+lt,ed); } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); q[++t].op=0; q[t].x=i; q[t].z=a[i]; q[t].y=1; } for(int i=1;i<=m;i++){ char ch[2]; int x,y; scanf("%s",ch); if(ch[0]==‘C‘){ scanf("%d%d",&x,&y); q[++t].op=-1; q[t].x=x; q[t].z=a[x]; q[t].y=-1; q[++t].op=0; q[t].x=x; q[t].z=y; q[t].y=1; a[x]=y; } else { scanf("%d%d%d",&q[t+1].x,&q[t+1].y,&q[t+1].z); q[++t].op=++num; } } solve(-10,10,1,t); for(int i=1;i<=num;i++) printf("%d\n",ans[i]); return 0; }
标签:== ranking highlight change while %s char mic scanf
原文地址:https://www.cnblogs.com/Hikigaya/p/10588567.html