提交时间:2021-12-13 13:36:59

运行 ID: 35093

#include <bits/stdc++.h> using namespace std; long long a[8005]; struct node { int son[2], vis; } t[5000005]; int pos=1; void Add(long long x) { int p=1; ++t[p].vis; for (int i=63; i>=0; --i) { bool b=(x>>i) & 1; if (!t[p].son[b]) t[p].son[b]=++pos; p = t[p].son[b]; ++t[p].vis; } } void Del(long long x) { int p=1; --t[p].vis; for (int i=63; i>=0; --i) { p=t[p].son[(x>>i) & 1]; if (p) --t[p].vis; } } int Sum(long long x) { int ans=0, p=1; for (int i=63; i>=0; --i) { bool b = (x>>i) & 1; if (b) ans+=t[t[p].son[0]].vis; p=t[p].son[b]; if (!p) return ans; } return ans; } int main() { int n,q; cin >> n >> q; for (int i = 1; i <= n; ++i) { cin >> a[i]; Add (1ll * (a[i] * n + i)); } for (int i = 1,opt,x,v; i <= q; ++i) { cin >> opt >> x; if (opt == 1) { cin >> v; Del (1ll * (a[x] * n + x)); a[x] = v; Add (1ll * (a[x] * n + x)); } else cout << Sum (1ll * (a[x] * n + x) + 1) << '\n'; } return 0; }