"Bzoj 2120" number color

Source: Internet
Author: User

Description

Ink bought a set of n color brushes (some of which may be the same color), in a row, you need to answer the ink question. Ink will be like you publish the following command: 1, Q L R represents a number of different colors from the L-brush to the R-branch brush. 2, R P Col replaces the P-branch brush with the color col. Do you know what you need to do to meet the requirements of ink and ink?

Input

The 1th line of two integer n,m, respectively, represents the number of initial brushes and the number of things the ink will do. The 2nd row n integers, representing the color of the I-pen in the original brush row, respectively. Line 3rd to 2+m, each line represents the ink will do one thing, the format of the cadre points.

Output

For each query, you need to give a number in the corresponding line, representing the brush of the L-pen to the R-branch brush in a total of several different colors.

Sample Input6 5
1 2 3 4 5 5
Q 1 4
Q 2 6
R 1 2
Q 1 4
Q 2 6
Sample Output4
4
3
4
HINT

For 100% of data, n≤10000,m≤10000, no more than 1000 modifications, all the integers appearing in the input data are greater than or equal to 1 and no more than 10^6.

What is the positive solution? I do not know the idea of reference hzwer, this problem can be violent sub-block, because less modification. Record the last occurrence of each color in that, and then arrange the order. On the edge of violence to find a smaller than the previous point, the two points in the block said Lower_bound is the query before the open interval ...
1#include <cstdio>2#include <cmath>3#include <iostream>4#include <algorithm>5 using namespacestd;6 Const intn=10010;7 intbel[n],last[1000001],size[n],pre[n],q[n],a[n],c[n];8 intNum,n,m,l,r,p,col,ans;9  Ten voidbuild () { One     intblock=sqrt (n); A      for(intI=1; i<=n;i++){ -bel[i]= (I-1)/block+1; -         if(Bel[i]>num) num=Bel[i]; thesize[bel[i]]++; -pre[i]=Last[a[i]]; -c[i]=Pre[i]; -last[a[i]]=i; +     } - } +   A voidResetintx) { at      for(inti=q[x-1]+1; i<=q[x];i++) pre[i]=C[i]; -Sort (pre+q[x-1]+1, pre+q[x]+1); - } -   - intFindintXinty) { -     intTmp=lower_bound (pre+q[x-1]+1, pre+q[x]+1, y)-pre-q[x-1]-1; in     returntmp; - } to   + intAskintLintR) { -     if(bel[l]==Bel[r]) { the          for(inti=l;i<=r;i++)if(c[i]<l) ans++; *     } $     Else{Panax Notoginseng          for(inti=l;i<=q[bel[l]];i++)if(c[i]<l) ans++; -          for(inti=q[bel[r]-1]+1; i<=r;i++)  the         if(c[i]<l) ans++; +     } A      for(inti=bel[l]+1; i<bel[r];i++) ans+=find (i,l); the     returnans; + } -   $ voidChangeintXinty) { $      for(intI=1; i<=n;i++) last[a[i]]=0; -a[x]=y; -      for(intI=1; i<=n;i++){ the         intt=C[i]; -c[i]=Last[a[i]];Wuyi         if(t!=c[i]) reset (bel[i]); thelast[a[i]]=i; -     } Wu } -   About intMain () { $scanf"%d%d",&n,&m); -      for(intI=1; i<=n;i++) scanf ("%d",&a[i]); - build (); -      for(intI=1; i<=num;i++) q[i]=q[i-1]+Size[i]; A      for(intI=1; i<=num;i++)  + Reset (i); the     Chars[4]; -      for(intI=1; i<=m;i++){ $scanf"%s", s); the         if(s[0]=='Q'){ theans=0; thescanf"%d%d",&l,&R); theprintf"%d\n", Ask (L,r)); -         } in         Else{ thescanf"%d%d",&p,&col); the Change (p,col); About         } the     } the}

"Bzoj 2120" number color

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.