F. Machine learning with fixed end MO Team

Source: Internet
Author: User

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:

  1. 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 }
  2. 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&LT;A.TIM:R&LT;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&LT;Q[I].L) Modify (a[l],-1),++l;  while(L&GT;Q[I].L) Modify (a[l-1],1),--l;  while(R&LT;Q[I].R) Modify (a[r+1],1),++R;  while(R&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.