提交时间:2024-03-26 16:37:30

运行 ID: 139884

#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; struct Node{ int son[2], sz; Node(): sz(0) { son[0] = son[1] = 0; } }; struct Trie01{ static const int MAXD = 42; vector<Node> nodes; Trie01() { nodes.resize(2); } void add(ull x, int val){ int cur(1); nodes[cur].sz += val; for (int i(MAXD); ~i; --i) { int dg(x >> i & 1); if (!nodes[cur].son[dg]) nodes[cur].son[dg] = nodes.size(), nodes.push_back(Node()); cur = nodes[cur].son[dg]; nodes[cur].sz += val; } } int getidx(ull x) const{ int cur(1), res(0); for (int i(MAXD); ~i; --i) { int dg(x >> i & 1); if (dg) res += nodes[nodes[cur].son[0]].sz; cur = nodes[cur].son[dg]; } return res; } }; int read(){ int x(0); char c(getchar()); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x; } int main(){ Trie01 trie; int N(read()), Q(read()); vector<int> nums(N); for (int i(0); i != N; ++i) { nums[i] = read(); trie.add(nums[i] * 1ULL * N + i, 1); } for (int opt, x; Q--; ) { opt = read(), x = read() - 1; if (opt == 1) { trie.add(nums[x] * 1ULL * N + x, -1); nums[x] = read(); trie.add(nums[x] * 1ULL * N + x, 1); } else printf("%d\n", trie.getidx(nums[x] * 1ULL * N + x) + 1); } return 0; }