2453: Maintenance Queue time limit:10 Sec Memory limit:128 MB
submit:578 solved:247
[Submit] [Status] [Discuss] Description did you play marbles when you were a kid? Children A have some marbles, a like to queue them, from left to right numbered 1 to N. For the whole queue to be bright and beautiful, the children want to know how many different colored marbles are in a continuous marble. Of course, a sometimes replaces the color of one of the marbles in the queue, depending on your preference. But a has not learned to program, and think brainstorming is too wasteful of brain power, so ask you for help. The first line of the input file contains two integers n and M. The second row n integers representing the color of the initial queue shot. Next m line, each line in the form of "Q L R" or "R x C", "Q L R" indicates that a want to know from the queue L to the first marbles, there are a total number of different colors of the marbles, "R x C" means a to the X position of the marbles replaced by the C color. Output for each q operation, a row of outputs indicates the query result. Sample Input
2 3
1 2
Q 1 2
R 1 2
Q 1 2
Sample Output2
1HINT
For 100% of the data, there are 1≤n≤10000, 1≤m≤10000, children A will not be modified more than 1000 times, all colors are 1 to 10^6 integer representation.
Source
2011 Fujian Training
1#include <bits/stdc++.h>2 using namespacestd;3 #defineMAXN 100104 #defineMAXM 10000105 intN,A[MAXN],LAST[MAXN],PRE[MAXM],BLOCK,POS[MAXN],H[MAXN];6 intRead ()7 {8 ints=0, fh=1;CharCh=GetChar ();9 while(ch<'0'|| Ch>'9'){if(ch=='-') fh=-1; ch=GetChar ();}Ten while(ch>='0'&&ch<='9') {s=s*Ten+ (ch-'0'); ch=GetChar ();} One returns*fh; A } - voidClintk) - { the intL= (K-1) *block+1, R=min (n,k*block), I; - for(i=l;i<=r;i++) a[i]=Last[i]; -Sort (a+l,a+r+1); - } + voidChange (intXintc) - { + inti,t; A for(i=1; i<=n;i++) pre[h[i]]=0; ath[x]=C; - for(i=1; i<=n;i++) - { -t=Last[i]; -last[i]=Pre[h[i]]; - if(t!=Last[i]) cl (pos[i]); inpre[h[i]]=i; - } to } + intFind (intKintll) - { the intL= (K-1) *block+1, R=min (k*block,n), mid,t=0; * while(l<=R) $ {Panax NotoginsengMid= (L+R)/2; - if(A[MID]>=LL) r=mid-1; the Else if(A[MID]<LL) t=mid,l=mid+1; + } A if(t==0)return 0; the Else returnT (K-1) *block+1)+1; + } - intQuery (intLintR) $ { $ intans=0, I; - if(pos[l]==Pos[r]) - { the for(i=l;i<=r;i++)if(last[i]<l) ans++; - }Wuyi Else the { - for(i=l;i<=pos[l]*block;i++)if(last[i]<l) ans++; Wu for(I= (pos[r]-1) *block+1; i<=r;i++)if(last[i]<l) ans++; - for(i=pos[l]+1; i<=pos[r]-1; i++) ans+=Find (i,l); About } $ returnans; - } - intMain () - { A intm,i,m,s1,s2; + Charfh[2]; theN=read (); m=read (); -Block= (int) sqrt (n); $Memset (Last,0,sizeof(last)); thememset (PRE,0,sizeof(pre)); the for(i=1; i<=n;i++) the { theh[i]=read (); -last[i]=Pre[h[i]]; inpre[h[i]]=i; thepos[i]= (I-1)/block+1; the } About if(block*block==n) m=n/Block; the Elsem=n/block+1; the for(i=1; i<=m;i++) cl (i); the for(i=1; i<=m;i++) + { -scanf"\n%s", FH); S1=read (); s2=read (); the if(fh[0]=='Q')Bayi { theprintf"%d\n", Query (S1,S2)); the } - ElseChange (S1,S2); - } the return 0; the}
View Code
1#include <bits/stdc++.h>2 using namespacestd;3 inta[10010];4bitset<1000010>Vis;5 intMain ()6 {7 intn,m,i,l,r,sum,j;8 Charfh;9scanf"%d%d",&n,&m);Ten for(i=1; i<=n;i++) scanf ("%d",&a[i]); One for(i=1; i<=m;i++) A { -scanf"\n%c%d%d",&fh,&l,&R); - if(fh=='Q') the { - Vis.reset (); -sum=0; - for(j=l;j<=r;j++)if(vis[a[j]]==0) {sum++;vis[a[j]]=1;} +printf"%d\n", sum); - } + Else A { ata[l]=R; - } - } - return 0; -}
View Code
Bzoj 2453: Maintenance queue && Bzoj 2120: Number of color tiles, bitset