版本比较
题解:P3960 [NOIP 2017 提高组] 列队
正文
增加 9 行删除 9 行
17 行未改动18192021222223242425262727282930303132333435363637383940414243444545464748492 行未改动5253545556565758595960616263646566666768697010 行未改动17 行未改动
```cpp#include<bits/stdc++.h>#define int long longusing namespace std;//要开long long我这里直接define了 using namespace std;//要开long long我这里直接define了const int N=6e5+5,M=2e7+5;//写线段树数组要开大,防止RE //写线段树数组要开大,防止REstruct STree{ int l,r; int sz,id;//子树大小和节点编号 int sz,id;//子树大小和节点编号}t[M];int n,m,q,rt[N],op[N],cnt;//分别指行数,列数,询问次数,各树深度,修改次数,编号的增量 //分别指行数,列数,询问次数,各树深度,修改次数,编号的增量int zzz;inline void newnode(int &p,int l,int r,bool op){ p=++cnt; t[p].sz=!op?max(0LL,min(n,r)-l+1):max(0LL,min(m-1,r)-l+1); t[p].id=!op?(l*m):((zzz-1)*m+l);}//建一个新节点并更新其子树和编号 }//建一个新节点并更新其子树和编号inline int find(int &p,int l,int r,int pos,bool op){ if (!p) newnode(p,l,r,op); --t[p].sz; if (l==r) return t[p].id; int mid=l+r>>1; if (!t[p].l) newnode(t[p].l,l,mid,op); if (pos<=t[t[p].l].sz) return find(t[p].l,l,mid,pos,op); else return find(t[p].r,mid+1,r,pos-t[t[p].l].sz,op);}//查找编号 }//查找编号inline void update(int &p,int l,int r,int pos,int v,bool op){ if (!p) newnode(p,l,r,op); ++t[p].sz; if (l==r){2 行未改动 } int mid=l+r>>1; if (pos<=mid) update(t[p].l,l,mid,pos,v,op); else update(t[p].r,mid+1,r,pos,v,op);}//更新编号 }//更新编号signed main(){ cin>>n>>m>>q; int len=max(n,m)+q;//因为动态开点,所以要留够空间 int len=max(n,m)+q;//因为动态开点,所以要留够空间 for (int i=1;i<=q;i++){ int x,y; cin>>x>>y; if (y==m){ int ans=find(rt[n+1],1,len,x,0); printf("%lld\n",ans); ++op[n+1];//更新操作次数 ++op[n+1];//更新操作次数 update(rt[n+1],1,len,n+op[n+1],ans,0); }else{ zzz=x; int ans=find(rt[x],1,len,y,1);10 行未改动