#include <bits/stdc++.h>
using namespace std;

class DSU {
private:
  vector<int> rank, parent;
  vector<unordered_map<int, int>> freq;

public:
  DSU(vector<int> &init) {
    int sz = init.size();
    rank = vector<int>(sz, 0);
    parent = vector<int>(sz, 0);
    iota(parent.begin(), parent.end(), 0);
    freq = vector<unordered_map<int, int>>(sz);
    for (int i = 0; i < sz; ++i) {
      freq[i][init[i]] = 1;
    }
  }

  int Find(int x) {
    if (parent[x] != x) {
      parent[x] = Find(parent[x]);
    }
    return parent[x];
  }

  bool Union(int x, int y) {
    int rootX = Find(x), rootY = Find(y);
    if (rootX == rootY) {
      return false;
    }

    if (rank[rootX] == rank[rootY]) {
      ++rank[rootX];
    }

    if (rank[rootX] < rank[rootY]) {
      swap(x, y);
      swap(rootX, rootY);
    }

    // rootX has higher rank
    parent[rootY] = rootX;

    for (pair<int, int> class_freq : freq[rootY]) {
      freq[rootX][class_freq.first] += class_freq.second;
    }
    return true;
  }

  int GetCount(int x, int c) {
    int root = Find(x);
    return freq[root][c];
  }
};

int32_t main() {
  int N, Q;
  cin >> N >> Q;
  vector<int> C(N);
  for (int i = 0; i < N; ++i)
    cin >> C[i];
  
  DSU dsu(C);
  for (int q = 0; q < Q; ++q) {
    int t;
    cin >> t;
    if (t == 1) {
      int a, b;
      cin >> a >> b;
      dsu.Union(a - 1, b - 1);
    } else {
      int x, y;
      cin >> x >> y;
      cout << dsu.GetCount(x - 1, y) << '\n';
    }
  }

  return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=2e5+1;
struct BIT{
	ll bit[200004];
	int dat[200004];
	void init(){
		for(int i=0;i<=M;i++)bit[i]=dat[i]=0;
	}
	void add(int id,int a,int b){
		for(;id;id-=(id&-id))dat[id]+=a,bit[id]+=b;
	}
	ll got1(int id){
		ll res=0;
		for(;id<=M;id+=(id&-id))res+=bit[id];
		return res;
	}
	int got2(int id){
		int res=0;
		for(;id<=M;id+=(id&-id))res+=dat[id];
		return res;
	}
}X,Y;
vector<int>all;
int n,m,Q;
ll ans=0;
int a[200005],b[200004];
int x[200004],y[200004],t[200004];
ll gotx(int t){
	return Y.got1(t)+(ll)(m-Y.got2(t))*all[t];
}
ll goty(int t){
	return X.got1(t)+(ll)(n-X.got2(t))*all[t];
}
int main(){
	X.init(),Y.init();
	cin>>n>>m>>Q;
	all.push_back(0);
	for(int i=1;i<=Q;i++){
		cin>>t[i]>>x[i]>>y[i],all.push_back(y[i]);
	}
	all.push_back(-1);
	sort(all.begin(),all.end()),all.erase(unique(all.begin(),all.end()),all.end());
	for(int i=1;i<=n;i++)a[i]=1,X.add(1,1,0);
	for(int i=1;i<=m;i++)b[i]=1,Y.add(1,1,0);
	for(int i=1;i<=Q;i++){
		y[i]=lower_bound(all.begin(),all.end(),y[i])-all.begin();
		if(t[i]==1){
			ans-=gotx(a[x[i]]);X.add(a[x[i]],-1,-all[a[x[i]]]);
			a[x[i]]=y[i];
			ans+=gotx(a[x[i]]);X.add(a[x[i]],1,all[a[x[i]]]);
		}else{
			ans-=goty(b[x[i]]);Y.add(b[x[i]],-1,-all[b[x[i]]]);
			b[x[i]]=y[i];
			ans+=goty(b[x[i]]);Y.add(b[x[i]],1,all[b[x[i]]]);
		}
		cout<<ans<<"\n";
	}
}