I TM is really a brother. . .
Meaning of the questions:
Give the number of a series of 1-N
Every time you can put the value of a position of +1000000
Or to find a value, all a [1] ... a [r] is the number of sequences can not be equal to this value, and this value> w
At that time the game feel sure the tree cover tree section to be repaired first big K, one would not be on the autistic. . .
In fact, the other way round, if a [1] .... a [r] number sequence can not be equal to this value, then in fact we can from a [r + 1] .... [n] a find first value> = w
But consider this question with a modification, you will find this added value is very large, larger than n, then once a location added to this value, which is no longer produced contribution
This value is equivalent to delete.
We consider these values to save them, because once this value is deleted, it means that it is possible as the answer.
We have established a President of the trees, and implement the query is greater than> = w number of numbers, as well as a small range of operating on K, and to delete the number set into the inside
We look inside the range> = the number of w, if this value is 0, the number of which we delete the query whether there are larger than w, if not, the answer is n + 1, otherwise it is set inside the first is greater than w the number can be used to achieve lower_bound
0 is not considered, we checked the first r-l + 1 num (the number is greater than num) + This will be found in the first interior region> = w digital
Then a first query> = w in the set of numbers which, as may be the 1-r interval is deleted and the number of log ratio within the range n to r + 1> = w better answer number
It takes a minimum value to both.
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<set> using namespace std; const int maxx = 2e5+6; struct node{ int l,r; int cnt; }tree[maxx*40]; int root[maxx]; int cnt; set<int>s; int a[maxx]; void inserts(int l,int r,int pre,int &now,int pos){ now=++cnt; tree[now]=tree[pre]; tree[now].cnt++; if(l==r){ return ; } int mid=(l+r)>>1; if (pos<=mid){ inserts(l,mid,tree[pre].l,tree[now].l,pos); }else{ inserts(mid+1,r,tree[pre].r,tree[now].r,pos); } } int query(int L,int R,int l,int r,int w){ if (l==r){ return tree[R].cnt-tree[L].cnt; } int mid=(l+r)>>1; if (w<=mid){ return tree[tree[R].r].cnt-tree[tree[L].r].cnt+query(tree[L].l,tree[R].l,l,mid,w); }else { return query(tree[L].r,tree[R].r,mid+1,r,w); } } int Kth(int L,int R,int l,int r,int k){ if (l==r){ return l; } int mid=(l+r)>>1; int s=tree[tree[R].l].cnt-tree[tree[L].l].cnt; if (s>=k){ return Kth(tree[L].l,tree[R].l,l,mid,k); }else { return Kth(tree[L].r,tree[R].r,mid+1,r,k-s); } } int main(){ int t; int n,m; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); s.clear(); memset(tree,0,sizeof(tree)); memset(root,0,sizeof(root)); cnt=0; for (int i=1;i<=n;i++){ scanf("%d",&a[i]); inserts(1,n,root[i-1],root[i],a[i]); } int op; int r,w,pos=0; int ans=0; while(m--){ scanf("%d",&op); if (op==1){ scanf("%d",&pos); pos=pos^ans; s.insert(a[pos]); }else { scanf("%d%d",&r,&w); r=r^ans; w=w^ans; int num=query(root[r],root[n],1,n,w); if (num==0){ auto it=s.lower_bound(w); if (it!=s.end()){ ans=*it; printf("%d\n",*it); }else { ans=n+1; printf("%d\n",ans); } }else { auto it=s.lower_bound(w); if (it!=s.end()){ ans=min(Kth(root[r],root[n],1,n,n-r+1-num),*it); }else { ans=Kth(root[r],root[n],1,n,n-r+1-num); } printf("%d\n",ans); } } } } return 0; }