#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+1000;
int n,q,c[maxn],fa[maxn];
map<int,int> a[maxn];
void read(int &x)
{
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
int getfa(int x)
{
	if(fa[x]==x) return x;
	else return fa[x]=getfa(fa[x]);
}
void join(int x,int y)
{
	if(getfa(x)==getfa(y)) return;
	if(a[getfa(x)].size()<a[getfa(y)].size()) swap(x,y);
	for(pair<int,int>lll:a[getfa(y)]) a[getfa(x)][lll.first]+=lll.second;
	fa[getfa(y)]=getfa(x);
}
int main()
{
	read(n),read(q);
	for(int i=1;i<=n;i++) read(c[i]);
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=n;i++) a[i][c[i]]++;
	while(q--)
	{
		int x,y,z;
		read(x),read(y),read(z);
		if(x==1) join(y,z);
		else printf("%d\n",a[getfa(y)][z]);
	}
	return 0;
}

#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <math.h>

using namespace std;

#define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++)
#define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff)
#define mod 1000000007
#define cdeb(val) cout << #val << ":" << val << endl;
#define pdeb(val) printf("%s : %lld\n", #val, val);

typedef long long int ll;
typedef pair<ll, ll> P;

struct BIT {
  ll n;
  vector<ll> b;
  BIT(ll idx) : n(idx+1), b(n, 0) {}

  void init(vector<ll> a) {
    for(ll i = 0; i < a.size(); i++) {
      add(i+1, a[i]);
    }
  }

  // sum: b[1] ~ b[i];
  ll sum(ll i) {
    ll ret = 0;
    while(i > 0) {
      ret += b[i];
      i -= i & -i;
    }
    return ret;
  }

  // sum: b[x] ~ b[y];
  ll range_sum(ll x, ll y) {
    return sum(y) - sum(x-1);
  }

  void add(ll i, ll x) {
    while(i <= n) {
      b[i] += x;
      i += i & -i;
    }
  }
};

int main(){
  ll n;
  cin >> n;

  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  BIT b(n);

  ll total = 0;

  rep(i, n) {
    total += a[i] - b.sum(a[i]+1);
    b.add(a[i]+1, 1);
  }
  
  rep(i, n) {
    cout << total << endl;
    total = (total - a[i]) + (n - 1 - a[i]);
  }
  return 0;
}
