rt,请问一下我的莫队哪里写假了。
#include <bits/stdc++.h>
#define int long long
#define maxm 2000005
#define maxn 1005
#define inf 0x3f3f3f3f3f3f
using namespace std;
int t,n,m,block,sum;
int a[maxm],pos[maxm],ans[maxm];
unordered_map<int,int>vis;
int cntq,cntm,l=1,r,Time;
struct node{
int l,r,t,id;
}q[maxm];
struct kkk{
int x,y;
}q1[maxm];
bool cmp(node x,node y){
if(pos[x.l]!=pos[y.l])return pos[x.l]<pos[y.l];
if(pos[x.r]!=pos[y.r])return pos[x.r]<pos[y.r];
return x.t<y.t;
}
void add(int x){
vis[a[x]]++;
if(vis[a[x]]==1)sum++;
if(vis[a[x]]==2)sum--;
}
void del(int x){
vis[a[x]]--;
if(!vis[a[x]])sum--;
if(vis[a[x]]==1)sum++;
}
void work(int x,int i){
if(q[i].l<=q1[x].x&&q[i].r>=q1[x].x){
del(q1[x].x);
vis[q1[x].y]++;
if(vis[q1[x].y]==1)sum++;
if(vis[q1[x].y]==2)sum--;
}
swap(a[q1[x].x],q1[x].y);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
block=pow(n,2.0/3.0);
for(int i=1;i<=n;i++){
cin>>a[i];
pos[i]=(i-1)/block+1;
}
for(int i=1;i<=m;i++){
int op,x,y;
cin>>op>>x>>y;
x++,y++;
if(op==1)y--,q1[++cntm]=(kkk){x,y};
else q[++cntq]=(node){x,y,cntm,cntq};
}
sort(q+1,q+cntq+1,cmp);
for(int i=1;i<=cntq;i++){
while(l>q[i].l)add(--l);
while(r<q[i].r)add(++r);
while(l<q[i].l)del(l++);
while(r>q[i].r)del(r--);
while(Time<q[i].t)work(++Time,i);
while(Time>q[i].t)work(Time--,i);
ans[q[i].id]=sum;
}
for(int i=1;i<=cntq;i++)cout<<ans[i]<<"\n";
return 0;
}