提交时间:2023-08-16 11:53:34

运行 ID: 98588

#include<bits/stdc++.h> using namespace std; inline int read() { int x=0,f=1; char c=getchar(); while(c>'9'||c<'0') { if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); } return x*f; } int n,m,k; int tot,ctot; struct tmp { int l,r,id,pre; }G[100010]; struct node { int where,pos; }C[100010]; int a[100010]; int block[400010]; int ans; int cnt[1000010]; int cmp(tmp a,tmp b) { if(block[a.l]==block[b.l]) return a.r<b.r; else return block[a.l]<block[b.l]; } int Add(int x) { if(cnt[x]==0) ans++; cnt[x]++; } int Del(int x) { if(cnt[x]==1) ans--; cnt[x]--; } int work(int now,int i) { if(C[now].where>=G[i].l&&C[now].where<=G[i].r) { if(--cnt[a[C[now].where]]==0) ans--; if(++cnt[C[now].pos]==1) ans++; } swap(C[now].pos,a[C[now].where]); } int bala[100010]; void moqueue() { int L=1,R=n; int now=0; for(int i=1;i<=tot;i++) { while(L<G[i].l)Del(a[L]),L++; while(R>G[i].r)Del(a[R]),R--; while(L>G[i].l)L--,Add(a[L]); while(R<G[i].r)R++,Add(a[R]); while(now<G[i].pre) work(++now,i); while(now>G[i].pre) work(now--,i); bala[G[i].id]=ans; } for(int i=1;i<=tot;i++) printf("%d\n",bala[i]); } int main() { //freopen("karry5307.in","r",stdin); //freopen("karry5307","w",stdout); n=read(),m=read(); int blk=sqrt(n); for(int i=1;i<=n;i++) block[i]=(i-1)/blk+1; for(int i=1;i<=n;i++) { a[i]=read(); Add(a[i]); } tot=0,ctot=0; for(int i=1;i<=m;i++) { int c; c=read(); if(c==2) G[++tot].l=read(),G[tot].r=read(),G[tot].id=tot,G[tot].pre=ctot; if(c==1) { int l,r; l=read(),r=read(); C[++ctot].where=l; C[ctot].pos=read(); } } sort(G+1,G+1+tot,cmp); moqueue(); return 0; }