版本比较
123
正文
增加 39 行删除 55 行
12344566789891011111213141516131718151920172122192324212225262728293031323334353637252627282930313233343839373839404041424344454642434445474748495051525354555657484950515952536162635455565758596566676869707172737475606162```#include<bits/stdc++.h>using namespace std;int n,a[1000001],stk[1000001],ans[1000001],tree[1000001];const int inf=1e9;int a[200001];struct node{ int l,r,val,id; int mx; node *l,*r;};node f[2000001];bool cmp(node x,node y)node *build(){ return x.l>y.l||x.l==y.l&&(x.r<y.r||x.r==y.r&&x.id<y.id); node *head=new node; head->mx=0; head->l=head->r=NULL; return head;}int lowbit(int x)void pushup(node *head){ return x&-x; head->mx=max(head->l->mx,head->r->mx);}void edit(int x,int k)void edit(node *head,int l,int r,int x,int k){ while(x<=n) if(l==r) { tree[x]=max(tree[x],k); x+=lowbit(x); head->mx+=k; return; } if(head->l==NULL) head->l=build(); if(head->r==NULL) head->r=build(); if(x<=(l+r)/2) edit(head->l,l,(l+r)/2,x,k); else edit(head->r,(l+r)/2+1,r,x,k); pushup(head);}int query(int x){ int ans=0; while(x>0) { ans=max(ans,tree[x]); x-=lowbit(x); } return ans;}int main(){// freopen("c.in","r",stdin);// freopen("c.out","w",stdout); int m,cnt,top; cin>>n>>m; freopen("reorder.in","r",stdin); freopen("reorder.out","w",stdout); int n,q,p,x; node *head; cin>>n>>q; head=build(); for(int i=1;i<=n;i++) cin>>a[i]; top=0; cnt=0; for(int i=1;i<=n;i++) { while(top>0&&a[i]>=a[stk[top]]) top--; if(top>0) { cnt++; f[cnt].l=stk[top]; f[cnt].r=i; f[cnt].val=a[i]+a[stk[top]]; f[cnt].id=0; } stk[++top]=i; cin>>a[i]; edit(head,1,inf,a[i],1); } cout<<n-head->mx<<endl; for(int i=1;i<=m;i++) for(int i=1;i<=q;i++) { cnt++; cin>>f[cnt].l>>f[cnt].r>>f[cnt].val; f[cnt].id=i; cin>>p>>x; edit(head,1,inf,a[p],-1); a[p]=x; edit(head,1,inf,x,1); cout<<n-head->mx<<endl; } sort(f+1,f+cnt+1,cmp); for(int i=1;i<=cnt;i++) if(f[i].id==0) edit(f[i].r,f[i].val); else if(query(f[i].r)<=f[i].val) ans[f[i].id]=1; else ans[f[i].id]=0; for(int i=1;i<=m;i++) cout<<ans[i]<<endl; return 0;}```