Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
139884 | 陈家宝 | [CSP-J2021]插入排序 | C++ | 通过 | 100 | 103 MS | 11052 KB | 1377 | 2024-03-26 16:37:30 |
#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; }