提交时间:2021-12-06 19:14:38

运行 ID: 33519

#include <iostream> #include <cstdio> using namespace std; struct Node { int vis,son[2]; //分别是0,1两个儿子 }t[2000010]; long long a[200010]; int pos = 1; void Add(long long x) { int p = 1,i; t[p].vis++; for(i = 63;i >= 0;i--) { long long b = (x>>i)&1; if(!t[t[p].son[b]].vis) t[p].son[b] = ++pos; //建儿子树 p = t[p].son[b]; t[p].vis++; } return; } void Del(long long x) { int p = 1,i; t[p].vis--; for(i = 63;i >= 0;i--) { long long b = (x>>i)&1; t[t[p].son[b]].vis--; p = t[p].son[b]; } return; } int Query(long long x) //查找有多少个数小于x { long long ans = 0,p = 1,i; for(i = 63;i >= 0;i--) { long long b = (x>>i)&1ll; if(b) ans+=t[t[p].son[0]].vis; p = t[p].son[b]; } return ans; } int main() { //freopen("sort.in","r",stdin); //freopen("sort.out","w",stdout); int n,Q,i; cin>>n>>Q; for(i = 1;i <= n;i++) { cin>>a[i]; Add(1ll * (1ll * a[i] * n + (long long)i)); //映射 } while(Q--) { int opt; cin>>opt; if(opt == 1) { int x,v; cin>>x>>v; Del(1ll * (1ll * a[x] * n + (long long)x)); a[x] = v; Add(1ll * (1ll * a[x] * n + (long long)x)); } else { int x,i; cin>>x; cout<<Query(1ll * (1ll * a[x] * n + (long long)x)) + 1<<endl; //加一为当前位置 } } return 0; }