結果
問題 | No.2809 Sort Query |
ユーザー | Tatsu_mr |
提出日時 | 2024-08-11 20:15:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,416 bytes |
コンパイル時間 | 2,824 ms |
コンパイル使用メモリ | 226,540 KB |
実行使用メモリ | 61,860 KB |
最終ジャッジ日時 | 2024-08-11 20:17:14 |
合計ジャッジ時間 | 98,443 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 1,011 ms
30,952 KB |
testcase_12 | AC | 1,007 ms
30,948 KB |
testcase_13 | AC | 992 ms
30,952 KB |
testcase_14 | AC | 1,017 ms
30,952 KB |
testcase_15 | AC | 1,017 ms
30,948 KB |
testcase_16 | AC | 1,015 ms
31,076 KB |
testcase_17 | AC | 998 ms
30,952 KB |
testcase_18 | AC | 988 ms
30,948 KB |
testcase_19 | AC | 979 ms
30,952 KB |
testcase_20 | AC | 1,057 ms
30,952 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 954 ms
27,488 KB |
testcase_32 | AC | 964 ms
27,612 KB |
testcase_33 | AC | 952 ms
27,576 KB |
testcase_34 | AC | 967 ms
27,616 KB |
testcase_35 | AC | 957 ms
27,504 KB |
testcase_36 | AC | 883 ms
31,068 KB |
testcase_37 | AC | 835 ms
31,072 KB |
testcase_38 | AC | 861 ms
30,944 KB |
testcase_39 | AC | 847 ms
30,816 KB |
testcase_40 | AC | 958 ms
30,940 KB |
testcase_41 | AC | 1,735 ms
40,860 KB |
testcase_42 | AC | 1,648 ms
40,992 KB |
testcase_43 | AC | 1,705 ms
40,868 KB |
testcase_44 | AC | 1,739 ms
40,732 KB |
testcase_45 | AC | 1,694 ms
40,860 KB |
testcase_46 | AC | 1,186 ms
40,864 KB |
testcase_47 | AC | 1,201 ms
40,736 KB |
testcase_48 | AC | 1,205 ms
40,736 KB |
testcase_49 | AC | 1,253 ms
40,736 KB |
testcase_50 | AC | 1,199 ms
40,860 KB |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
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); queue<pair<int, lint>> wait; while (q--) { int t; cin >> t; if (t == 1) { int k; lint x; cin >> k >> x; k--; b[k] = x; wait.push({k, x}); } else if (t == 2) { while (!wait.empty()) { auto [k, x] = wait.front(); wait.pop(); if (b[k] != x) { continue; } b[k] = -1; tr.erase(tr[k]); tr.insert(x); } } else { int k; cin >> k; k--; cout << (b[k] != -1 ? b[k] : tr[k]) << endl; } } }