F. Machine Learningtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output
You come home and fell some unpleasant smell. Where is it coming from?
You is given an array a. You have to answer the following queries:
- You are given and integersLandR. LetCIBe the number of occurrences ofIIncha l : r , where a l : r is the subarray of a from l -th element to R -th inclusive. Find the mex of { C 0 , c 1 , ..., c 9 }
- You are given and integers p to x. Change ap to x.
The Mex of a multiset of numbers is the smallest non-negative an integer not in the set.
Note that the This problem all elements of a is positive, which means that C0 = 0 and 0 are never the answer for the query of the second type.
Input
The first line of input contains, integers n and q (1≤ n, Q ≤100 000) -the length of the array and the number of queries respectively.
The second line of input contains n integers- a1, a C16>2, ..., an (1≤ ai ≤109 ).
Each of the next Q Lines describes a single query.
The first type of query is described by three integers tI = 1, li, c12>Ri, where 1≤ li ≤ ri ≤ n -the bounds of the subarray.
The second type of query is described by three integers tI = 2, pi, x i, where 1≤ pi ≤ n is the index of the element, Which must be changed and 1≤ xi ≤109 is the new value.
Output
For each query of the first type output a single integer-the Mex of {C0, C 1, ..., c 9}.
Exampleinputcopy
10 4
1 2 3 1 1 2 2 2 9 9
1 1 1
1 2 8
2 7 1
1 2 8
Output
#include <cstdio>#include<cstring>#include<map>#include<cmath>#include<algorithm>using namespacestd;Const intn=2e5+ the; Map<int,int>M;intvis[n],num[n],a[n],b[n],now[n],ans[n],unit,l,r,t;structquery{intL,r,tim,id; BOOL operator< (ConstQuery &a)Const{ returnL/unit==a.l/unit? (R/UNIT==A.R/UNIT?TIM<A.TIM:R<A.R):l<A.L; }}q[n];structchange{intPos,x,y;} C[n];voidModifyintXintd) { --vis[num[x]];num[x]+=d;++vis[num[x]];}voidGoing (intTintd) { if(c[t].pos>=l&&c[t].pos<=r) Modify (c[t].x,d), modify (c[t].y,-d); if(d==1) a[c[t].pos]=c[t].x;Elsea[c[t].pos]=c[t].y;}intCalc () { for(intI=1;; ++i)if(!vis[i])returni;}intMain () {intN,q,tot,op,cc=0, pp=0; scanf ("%d%d",&n,&q); for(intI=1; i<=n;++i) scanf ("%d", &a[i]), now[i]=b[i]=A[i]; Tot=n,unit= (int) POW (n,0.6666666); for(intI=1; i<=q;++i) {scanf ("%d",&op); if(op==2){ ++CC,SCANF ("%d%d",&c[cc].pos,&c[cc].x); C[cc].y=now[c[cc].pos],b[++tot]=now[c[cc].pos]=c[cc].x; } Else { ++PP,SCANF ("%d%d",&q[pp].l,&Q[PP].R); Q[pp].tim=cc,q[pp].id=pp; }} sort (b+1, b+tot+1); Tot=unique (b +1, b+tot+1)-b-1; for(intI=1; i<=tot;++i) m[b[i]]=i; for(intI=1; i<=n;++i) a[i]=M[a[i]]; for(intI=1; i<=cc;++i) c[i].x=m[c[i].x],c[i].y=M[C[I].Y]; Sort (Q+1, q+pp+1); for(intI=1; i<=pp;++i) { while(T<q[i].tim) Going (t+1,1),++T; while(T>q[i].tim) Going (t,-1),--T; while(L<Q[I].L) Modify (a[l],-1),++l; while(L>Q[I].L) Modify (a[l-1],1),--l; while(R<Q[I].R) Modify (a[r+1],1),++R; while(R>Q[I].R) Modify (a[r],-1),--R; Ans[q[i].id]=Calc (); } for(intI=1; i<=pp;++i) printf ("%d\n", Ans[i]);}
2
3
2
MO Team Study Blog
F. Machine learning with fixed end MO Team