版本比较
123
正文
增加 41 行删除 88 行
12345645687891011101113121314151615171817192019212221222324252324272825262728293031323334353637313839333440414243444546473637484950394041424344454647484950515253545556575851525360616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105545556575859606162```#include<bits/stdc++.h>using namespace std;const int num=277200;int m,v[200002],s[200001],dp[200001],tree[200001];long long a[200001],c[200001],f[200001];const int inf=1e9;int a[200001];struct node{ long long t,x; int mx; node *l,*r;};node b[200001];bool cmp1(node x,node y)node *build(){ return x.x<y.x; node *head=new node; head->mx=0; head->l=head->r=NULL; return head;}bool cmp2(int x,int y)void pushup(node *head){ return c[x]<c[y]||c[x]==c[y]&&x<y; head->mx=max(head->l->mx,head->r->mx);}int lowbit(int x)void edit(node *head,int l,int r,int x,int k){ return x&-x;}void edit(int x,int k){ while(x<=m) 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 main(){ int ans=0; while(x>0) 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++) { ans=max(ans,tree[x]); x-=lowbit(x); cin>>a[i]; edit(head,1,inf,a[i],1); } return ans;}int binary_search(int l,int r,long long x){ if(l>r) return r; int mid=(l+r)/2; if(a[mid]<=x) return binary_search(mid+1,r,x); else return binary_search(l,mid-1,x);}int main(){ freopen("WOWO.in","r",stdin); freopen("WOWO.out","w",stdout); int temp,n,pos; long long l,end; cin>>temp; for(int i=1;i<=temp;i++) cout<<n-head->mx<<endl; for(int i=1;i<=q;i++) { cin>>n>>m>>l>>end; l*=num; end*=num; for(int j=1;j<n;j++) { cin>>a[j]; a[j]*=num; } a[n]=l; for(int j=1;j<=n;j++) { cin>>v[j]; f[j]=(a[j]-a[j-1])/v[j]+f[j-1]; } v[n+1]=1; for(int j=1;j<=m;j++) { cin>>b[j].x>>b[j].t; b[j].x*=num; b[j].t*=num; } m++; b[m].x=l; b[m].t=end; sort(b+1,b+m+1,cmp1); for(int j=1;j<=m;j++) { pos=binary_search(1,n,b[j].x); c[j]=b[j].t-(f[pos]+(b[j].x-a[pos])/v[pos+1]); s[j]=j; } if(c[m]<0) cout<<-1<<endl; else { sort(s+1,s+m+1,cmp2); for(int j=1;j<=m;j++) if(c[s[j]]>=0) { dp[s[j]]=query(s[j])+1; edit(s[j],dp[s[j]]); } cout<<m-dp[m]<<endl; for(int j=1;j<=m;j++) tree[j]=0; } cin>>p>>x; edit(head,1,inf,a[p],-1); a[p]=x; edit(head,1,inf,x,1); cout<<n-head->mx<<endl; } return 0;}```