Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define PB push_back
- #define ZERO (1e-10)
- #define INF (1<<29)
- #define CL(A,I) (memset(A,I,sizeof(A)))
- #define DEB printf("DEB!\n");
- #define D(X) cout<<" "<<#X": "<<X<<endl;
- #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
- typedef long long ll;
- typedef pair<ll,ll> pll;
- typedef vector<int> vi;
- typedef pair<int,int> ii;
- typedef vector<ii> vii;
- #define IN(n) int n;scanf("%d",&n);
- #define FOR(i, m, n) for (int i(m); i < n; i++)
- #define F(n) FOR(i,0,n)
- #define FF(n) FOR(j,0,n)
- #define FT(m, n) FOR(k, m, n)
- #define aa first
- #define bb second
- void ga(int N,int *A){F(N)scanf("%d",A+i);}
- #define MX (200005)
- #define SQ (4048)
- #define SZ (MX/SQ+1)
- int H[MX*2];
- struct MO{
- struct MOQ{int b,e,i,j;};
- vector<MOQ> T[SZ][SZ];
- int A[MX],L,N,K,M,U[MX],t[MX],X[MX];
- void CLR(){L=N=K=M=0;F(SZ)FF(SZ)T[i][j].clear();}
- void ADD(int a){A[N++]=a;}
- void QY(int b,int e){T[b/SQ][e/SQ].PB({min(b,e),max(b,e),M++,++L});}
- void UD(int b,int v){X[K]=b,U[K]=v,t[K++]=++L;}
- int GO(int*O){
- int b,e;
- st();
- F(SZ)FF(SZ)if(!T[i][j].empty())b=e=T[i][j][0].b-1,i=j=INF;
- F(SZ)FF(SZ)if(!T[i][j].empty())pro(T[i][j],b,e,O);
- return M;
- }
- void pro(vector<MOQ>&T,int&b,int&e,int*O){
- int I=0;
- F((int)T.size()){
- while(b>=T[i].b)add(b--);
- while(e<T[i].e)add(++e);
- while(b+1<T[i].b)del(++b);
- while(e>T[i].e)del(e--);
- while(I<K&&T[i].j>t[I]){
- if(X[I]>b&&X[I]<=e)del(X[I]);
- swap(A[X[I]],U[I]);
- if(X[I]>b&&X[I]<=e)add(X[I]);
- ++I;
- }
- O[T[i].i]=ans();
- }
- while(~--I){
- if(X[I]>b&&X[I]<=e)del(X[I]);
- swap(A[X[I]],U[I]);
- if(X[I]>b&&X[I]<=e)add(X[I]);
- }
- }
- //MO
- int P,Z[MX];
- void add(int w){
- w=A[w];
- // printf("ADD: %d\n",w);
- if(++Z[w]==1)++P;
- else if(Z[w]==2)--P;
- }
- void del(int w){
- w=A[w];
- // printf("DEL: %d\n",w);
- if(!--Z[w])--P;
- else if(Z[w]==1)++P;
- }
- int ans(){
- // printf(" ANS: %d\n",P);
- return P;
- }
- void st(){}
- }T;
- int N,Q,a,b,c,O[MX];
- int main(void){
- scanf("%d%d",&N,&Q),T.CLR(),assert(0<N&&0<Q&&N<=2e5&&Q<=2e5);//ASS
- F(N)scanf("%d",&a),assert(a>=0&&a<=2e5),T.ADD(a);//ASS
- F(Q){
- scanf("%d%d%d",&a,&b,&c);
- assert(a==1||a==2);//ASS
- if(a-1)T.QY(b,c),assert(b>=0&&b<=c&&c<N);
- else T.UD(b,c),assert(b<N&&b>=0&&c>=0&&c<=2e5);
- }
- a=T.GO(O);
- F(a)printf("%d\n",O[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement