#include<bits/stdc++.h>
#define int long long
#define rint register int
#define per(i,a,b) for(rint (i)=(a);(i)>=(b);--(i))
#define rep(i,a,b) for(rint (i)=(a);(i)<=(b);++(i))
using namespace std;
inline int read()
{
	rint f=1,x=0;
	char c=getchar();
	while(c<'0'||c>'9')
	f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9')
	x=(x<<3)+(x<<1)+(c^'0'),c=getchar();
	return f*x;
}
const int N=1e5+10;
int tot,n,a[N],belong[N],L[N],R[N],pre[N],last[N],front[N],q;
signed main()
{
	//freopen("goodbye.in","r",stdin);
	//freopen("goodbye.out","w",stdout);
	n=read(),q=read();
	tot=sqrt(n);
	rep(i,1,n) a[i]=read();
	rep(i,1,n)
	{
		if(pre[a[i]]==0)
		pre[a[i]]=i;
		else
		last[i]=pre[a[i]],pre[a[i]]=i;
	}
	rep(i,1,q)
	{
		int opt=read(),x=read(),y=read();
		if(opt==1)
		{
			rep(i,x+1,n)
			if(a[i]==a[x])
			{
			    last[i]=last[x];
			    break;
			}
			per(i,x-1,1)
			if(a[i]==y)
			{
			    last[x]=i;
			    break;
			}
			rep(i,x+1,n)
			if(a[i]==y)
			{
			    last[i]=x;
			    break;
			}
			a[x]=y;
		}
		else
		{
			int res=0;
			rep(i,x,y)
			if(last[i]>=x&&last[i]!=0)
			res+=i-last[i];
			printf("%lld\n",res);
		}
	}
	return 0;
}
	 	    	 	 	 	   				 			 	  		