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.
Analysis
Well, the positive solution should be a tree-set tree, but ... Chunking can do ....
My method is very violent ... Changed the violent reconstruction. I can't believe it.
1 /*2 Song Dynasty3 Xin Qi4 Green Jade Case • Yuan Xi5 Dongfeng Night flowers thousand trees. More blowing, stars like rain. BMW Carving Car Incense full road. Feng Xiao Sound movement, jade pot light turn, one night fish dragon dance. 6 The golden wisp of the moth's snow willow. The laughter of the dark incense to go. The crowd sought him 1100 degrees. Suddenly look back, that person is in, the lights dim place. 7 */8#include <iostream>9#include <cstdio>Ten#include <algorithm> One#include <cstring> A#include <vector> -#include <utility> -#include <iomanip> the#include <string> -#include <cmath> -#include <queue> -#include <assert.h> +#include <map> -#include <ctime> +#include <cstdlib> A#include <stack> at#include <Set> - #defineLOCAL - Const intINF =100000000; - Const intMAXN =10000+Ten; - Const intMaxnode =20000*2+200000* -; - Const intmaxm=1000000+Ten; in using namespacestd; - inttot; to intN, Q, block_size; + intDATA[MAXN]; - intBELONG[MAXN], BLOCK[MAXN]; the intT[MAXN],LAST[MAXM]; * $ Panax Notoginseng //find out how many in the X block are smaller than v - intFindintXintv) { the intL = (X-1) * Block_size +1, r = min (x *block_size, n); + intFirst =l; A while(L <=R) { the intMid = (L + r) >>1; + if(Block[mid] < v) L = mid +1; - ElseR = Mid-1; $ } $ returnLFirst ; - } - intQueryintLintR) { the intAns =0; - if(Belong[l] = =Belong[r]) {Wuyi for(inti = l; I <= R; i++)if(T[i] < L) ans++; the}Else { - for(inti = l; I <= block_size * belong[l]; i++)if(T[i] < L) ans++; Wu for(inti = Block_size * (Belong[r]-1) +1; I <= R; i++)if(T[i] < L) ans++; - } About for(inti = Belong[l] +1; i < belong[r]; i++) ans + =Find (I, l); $ returnans; - } - //Processing Blocks - voidBuildintx) { A intL = (X-1) * Block_size +1, r = min (x *block_size, n); + for(inti = l; I <= R; i++) Block[i] =T[i]; theSort (Block + L, block + R +1);//sort the color of the last occurrence of a block - } $ //change the color of X to v the voidChangeintXintv) { the for(inti =1; I <= N; i++) Last[data[i] =0;//Violent Refactoring theDATA[X] =v; the for(inti =1; I <= N; i++){ - intTMP =T[i]; inT[i] =Last[data[i]]; the if(TMP! =T[i]) build (Belong[i]); theLast[data[i]] =i; About } the } the the voidinit () { +scanf"%d%d", &n, &q); - for(inti =1; I <= N; i++) scanf ("%d", &data[i]); theBlock_size = (int) (SQRT (n *1.0));Bayi //Tot records the total number of blocks thetot = n/block_size; the if(n% block_size) tot++; - - for(inti =1; I <= N; i++){ the //Linked-List insertion theT[i] =Last[data[i]]; theLast[data[i]] =i; theBelong[i] = (I-1)/Block_size +1; - } the for(inti =1; I <= tot; i++) {build (i); the } the }94 voidWork () { the for(inti =1; I <= Q; i++){ the Charstr[Ten]; thescanf"%s", str);98 if(str[0] =='Q'){ About intL, R; -scanf"%d%d", &l, &R);101printf"%d\n", Query (L, R));102}Else{103 intl, X;104scanf"%d%d", &l, &x); the Change (l, x);106 }107 }108 }109 the intMain () {111 the init ();113 Work (); the return 0; the}
View Code
"BZOJ2120" "Block List" number color