結果
問題 | No.2809 Sort Query |
ユーザー | Tatsu_mr |
提出日時 | 2024-08-11 21:13:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,557 ms / 2,000 ms |
コード長 | 5,884 bytes |
コンパイル時間 | 2,949 ms |
コンパイル使用メモリ | 229,076 KB |
実行使用メモリ | 69,960 KB |
最終ジャッジ日時 | 2024-08-11 21:14:50 |
合計ジャッジ時間 | 90,197 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1,238 ms
51,612 KB |
testcase_02 | AC | 1,198 ms
51,744 KB |
testcase_03 | AC | 1,200 ms
51,744 KB |
testcase_04 | AC | 1,220 ms
51,616 KB |
testcase_05 | AC | 1,260 ms
51,620 KB |
testcase_06 | AC | 1,018 ms
33,000 KB |
testcase_07 | AC | 1,041 ms
32,876 KB |
testcase_08 | AC | 1,037 ms
32,872 KB |
testcase_09 | AC | 1,012 ms
32,872 KB |
testcase_10 | AC | 1,049 ms
32,876 KB |
testcase_11 | AC | 982 ms
39,188 KB |
testcase_12 | AC | 922 ms
39,192 KB |
testcase_13 | AC | 962 ms
39,188 KB |
testcase_14 | AC | 928 ms
39,320 KB |
testcase_15 | AC | 979 ms
39,220 KB |
testcase_16 | AC | 949 ms
39,056 KB |
testcase_17 | AC | 915 ms
39,064 KB |
testcase_18 | AC | 950 ms
39,188 KB |
testcase_19 | AC | 960 ms
39,188 KB |
testcase_20 | AC | 957 ms
39,188 KB |
testcase_21 | AC | 1,545 ms
69,836 KB |
testcase_22 | AC | 1,523 ms
69,712 KB |
testcase_23 | AC | 1,457 ms
69,960 KB |
testcase_24 | AC | 1,465 ms
69,708 KB |
testcase_25 | AC | 1,457 ms
69,840 KB |
testcase_26 | AC | 1,440 ms
58,268 KB |
testcase_27 | AC | 1,420 ms
58,144 KB |
testcase_28 | AC | 1,452 ms
58,148 KB |
testcase_29 | AC | 1,399 ms
58,140 KB |
testcase_30 | AC | 1,390 ms
58,172 KB |
testcase_31 | AC | 947 ms
31,972 KB |
testcase_32 | AC | 920 ms
31,968 KB |
testcase_33 | AC | 963 ms
32,100 KB |
testcase_34 | AC | 967 ms
32,024 KB |
testcase_35 | AC | 911 ms
31,840 KB |
testcase_36 | AC | 895 ms
39,180 KB |
testcase_37 | AC | 811 ms
39,180 KB |
testcase_38 | AC | 818 ms
39,052 KB |
testcase_39 | AC | 848 ms
39,184 KB |
testcase_40 | AC | 852 ms
39,184 KB |
testcase_41 | AC | 1,499 ms
40,864 KB |
testcase_42 | AC | 1,548 ms
40,740 KB |
testcase_43 | AC | 1,554 ms
40,748 KB |
testcase_44 | AC | 1,549 ms
40,860 KB |
testcase_45 | AC | 1,557 ms
40,736 KB |
testcase_46 | AC | 1,170 ms
40,740 KB |
testcase_47 | AC | 1,229 ms
40,736 KB |
testcase_48 | AC | 1,149 ms
40,864 KB |
testcase_49 | AC | 1,156 ms
40,732 KB |
testcase_50 | AC | 1,084 ms
40,736 KB |
testcase_51 | AC | 912 ms
40,736 KB |
testcase_52 | AC | 852 ms
40,732 KB |
testcase_53 | AC | 842 ms
40,740 KB |
testcase_54 | AC | 919 ms
40,736 KB |
testcase_55 | AC | 842 ms
40,716 KB |
testcase_56 | AC | 1,152 ms
34,072 KB |
testcase_57 | AC | 798 ms
27,732 KB |
testcase_58 | AC | 750 ms
28,268 KB |
testcase_59 | AC | 868 ms
26,164 KB |
testcase_60 | AC | 921 ms
38,668 KB |
testcase_61 | AC | 1,162 ms
46,620 KB |
testcase_62 | AC | 819 ms
27,892 KB |
testcase_63 | AC | 1,090 ms
36,000 KB |
testcase_64 | AC | 1,472 ms
48,824 KB |
testcase_65 | AC | 705 ms
32,656 KB |
testcase_66 | AC | 2 ms
5,376 KB |
testcase_67 | AC | 2 ms
5,376 KB |
testcase_68 | AC | 2 ms
5,376 KB |
testcase_69 | AC | 2 ms
5,376 KB |
testcase_70 | AC | 1 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <class T> struct Treap { private: unsigned int xorshift() { static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned int t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } struct Node { Node *left, *right; T value, mx; int priority, size; Node (T value_, int priority_) : left(nullptr), right(nullptr), value(value_), mx(value_), priority(priority_), size(1) {} }; using N = Node *; N root = nullptr; T INF = numeric_limits<T>::max(); bool multi; map<T, int> mp; int cnt(N t) { return t ? t->size : 0; } T get_max(N t) { return t ? t->mx : -INF; } void update(N t) { if (t) { t->size = cnt(t->left) + cnt(t->right) + 1; t->mx = max({t->value, get_max(t->left), get_max(t->right)}); } } void merge(N &t, N l, N r) { if (!l || !r) { t = l ? l : r; } else if (l->priority > r->priority) { merge(l->right, l->right, r); t = l; } else { merge(r->left, l, r->left); t = r; } update(t); } void split(N t, T x, N &l, N &r) { if (!t) { l = nullptr; r = nullptr; } else if (x < t->value) { split(t->left, x, l, t->left); r = t; } else { split(t->right, x, t->right, r); l = t; } update(t); } void insert(N &t, N n) { if (!t) { t = n; } else if (n->priority > t->priority) { split(t, n->value, n->left, n->right); t = n; } else { insert(n->value < t->value ? t->left : t->right, n); } update(t); } void erase(N &t, T x) { if (t->value == x) { merge(t, t->left, t->right); } else { erase(x < t->value ? t->left : t->right, x); } update(t); } bool count(N &t, T x) { if (!t) { return false; } else if (t->value == x) { return true; } else { return count(x < t->value ? t->left : t->right, x); } } T kth(N t, int k) { int sz = cnt(t->left); if (sz == k) { return t->value; } return (sz > k ? kth(t->left, k) : kth(t->right, k - sz - 1)); } pair<T, int> search(N t, T x, int i, bool equal) { if (equal && t->value == x) { return {t->value, i}; } else if (x < t->value) { if ((equal && x <= get_max(t->left)) || (!equal && x < get_max(t->left))) { return search(t->left, x, i - cnt(t->left->right) - 1, equal); } else { return {t->value, i}; } } else { if (!(t->right)) { return {INF, -1}; } return search(t->right, x, i + cnt(t->right->left) + 1, equal); } } void dump(N t) { if (!t) { return; } dump(t->left); cout << t->value << " "; dump(t->right); } public: Treap(bool multi_ = false) : multi(multi_) {} Treap(vector<T> v, bool multi_ = false) : multi(multi_) { for (auto x : v) { insert(x); } } void insert(T x) { if (!multi && mp[x] > 0) { return; } mp[x]++; insert(root, new Node(x, xorshift())); } void erase(T x) { if (mp[x] > 0) { mp[x]--; erase(root, x); } } bool count(T x) { return count(root, x); } int size() { return cnt(root); } T operator[](int i) { assert(0 <= i && i < cnt(root)); return kth(root, i); } pair<T, int> lower(T x) { if (!root) { return {INF, -1}; } return search(root, x, cnt(root->left), true); } pair<T, int> upper(T x) { if (!root) { return {INF, -1}; } return search(root, x, cnt(root->left), false); } void dump() { dump(root); cout << endl; } }; using lint = long long; int main() { int n, q; cin >> n >> q; vector<lint> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } Treap<lint> tr(a, true); vector<lint> b(n, -1); vector<pair<int, lint>> wait; bool init = false; while (q--) { int t; cin >> t; if (t == 1) { int k; lint x; cin >> k >> x; k--; b[k] = x; wait.emplace_back(k, x); } else if (t == 2) { vector<lint> erase, insert; for (auto [k, x] : wait) { if (b[k] != x) { continue; } erase.emplace_back(init ? tr[k] : a[k]); insert.emplace_back(x); b[k] = -1; } for (auto x : erase) { tr.erase(x); } for (auto x : insert) { tr.insert(x); } wait.clear(); erase.clear(); init = true; } else { int k; cin >> k; k--; if (b[k] != -1) { cout << b[k] << endl; } else { cout << (init ? tr[k] : a[k]) << endl; } } /*tr.dump(); for (auto x : b) cout << x << " "; cout << endl << endl;*/ } }