結果
問題 | No.2809 Sort Query |
ユーザー | Tatsu_mr |
提出日時 | 2024-08-11 20:31:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,565 bytes |
コンパイル時間 | 3,044 ms |
コンパイル使用メモリ | 226,640 KB |
実行使用メモリ | 61,860 KB |
最終ジャッジ日時 | 2024-08-11 20:32:54 |
合計ジャッジ時間 | 93,911 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 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,039 ms
30,952 KB |
testcase_12 | AC | 1,027 ms
30,952 KB |
testcase_13 | AC | 1,017 ms
30,952 KB |
testcase_14 | AC | 981 ms
30,952 KB |
testcase_15 | AC | 984 ms
30,952 KB |
testcase_16 | AC | 1,033 ms
30,956 KB |
testcase_17 | AC | 1,000 ms
30,952 KB |
testcase_18 | AC | 978 ms
30,956 KB |
testcase_19 | AC | 949 ms
30,884 KB |
testcase_20 | AC | 963 ms
31,080 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 | 919 ms
27,492 KB |
testcase_32 | AC | 964 ms
27,620 KB |
testcase_33 | AC | 980 ms
27,620 KB |
testcase_34 | AC | 944 ms
27,492 KB |
testcase_35 | AC | 1,044 ms
27,484 KB |
testcase_36 | AC | 888 ms
30,948 KB |
testcase_37 | AC | 873 ms
30,948 KB |
testcase_38 | AC | 900 ms
30,944 KB |
testcase_39 | AC | 854 ms
30,904 KB |
testcase_40 | AC | 836 ms
30,940 KB |
testcase_41 | AC | 1,674 ms
40,740 KB |
testcase_42 | AC | 1,602 ms
40,736 KB |
testcase_43 | AC | 1,576 ms
40,732 KB |
testcase_44 | AC | 1,635 ms
40,864 KB |
testcase_45 | AC | 1,583 ms
40,736 KB |
testcase_46 | AC | 1,181 ms
40,704 KB |
testcase_47 | AC | 1,208 ms
40,736 KB |
testcase_48 | AC | 1,147 ms
40,736 KB |
testcase_49 | AC | 1,101 ms
40,860 KB |
testcase_50 | AC | 1,097 ms
40,740 KB |
testcase_51 | AC | 982 ms
40,864 KB |
testcase_52 | AC | 930 ms
40,764 KB |
testcase_53 | AC | 916 ms
40,740 KB |
testcase_54 | AC | 878 ms
40,736 KB |
testcase_55 | AC | 915 ms
40,736 KB |
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 | 3 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; bool init = false; 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); } init = true; } else { int k; cin >> k; k--; if (b[k] != -1) { cout << b[k] << endl; } else { cout << (init ? tr[k] : a[k]) << endl; } } } }