結果
問題 | No.2809 Sort Query |
ユーザー | Tatsu_mr |
提出日時 | 2024-08-06 01:37:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 7,890 bytes |
コンパイル時間 | 4,670 ms |
コンパイル使用メモリ | 279,236 KB |
実行使用メモリ | 72,860 KB |
最終ジャッジ日時 | 2024-08-06 01:39:28 |
合計ジャッジ時間 | 93,892 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 1,053 ms
71,596 KB |
testcase_12 | AC | 1,046 ms
71,724 KB |
testcase_13 | AC | 1,070 ms
71,660 KB |
testcase_14 | AC | 1,065 ms
71,596 KB |
testcase_15 | AC | 1,048 ms
71,596 KB |
testcase_16 | AC | 1,084 ms
71,600 KB |
testcase_17 | AC | 1,138 ms
71,596 KB |
testcase_18 | AC | 1,105 ms
71,596 KB |
testcase_19 | AC | 1,057 ms
71,592 KB |
testcase_20 | AC | 1,082 ms
71,596 KB |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | AC | 1,023 ms
60,064 KB |
testcase_32 | AC | 983 ms
59,780 KB |
testcase_33 | AC | 1,129 ms
59,896 KB |
testcase_34 | AC | 998 ms
59,788 KB |
testcase_35 | AC | 1,014 ms
59,652 KB |
testcase_36 | AC | 817 ms
71,668 KB |
testcase_37 | AC | 859 ms
72,808 KB |
testcase_38 | AC | 794 ms
72,860 KB |
testcase_39 | AC | 838 ms
72,352 KB |
testcase_40 | AC | 802 ms
72,368 KB |
testcase_41 | AC | 1,089 ms
51,604 KB |
testcase_42 | AC | 1,236 ms
50,812 KB |
testcase_43 | AC | 1,111 ms
50,440 KB |
testcase_44 | AC | 1,136 ms
50,264 KB |
testcase_45 | AC | 1,129 ms
51,648 KB |
testcase_46 | AC | 1,011 ms
50,372 KB |
testcase_47 | AC | 1,141 ms
50,512 KB |
testcase_48 | AC | 960 ms
51,488 KB |
testcase_49 | AC | 1,018 ms
51,472 KB |
testcase_50 | AC | 1,049 ms
50,268 KB |
testcase_51 | AC | 1,373 ms
50,940 KB |
testcase_52 | AC | 1,462 ms
50,332 KB |
testcase_53 | AC | 1,347 ms
50,564 KB |
testcase_54 | AC | 1,362 ms
50,712 KB |
testcase_55 | AC | 1,391 ms
50,464 KB |
testcase_56 | RE | - |
testcase_57 | RE | - |
testcase_58 | RE | - |
testcase_59 | RE | - |
testcase_60 | RE | - |
testcase_61 | RE | - |
testcase_62 | RE | - |
testcase_63 | RE | - |
testcase_64 | RE | - |
testcase_65 | RE | - |
testcase_66 | RE | - |
testcase_67 | WA | - |
testcase_68 | RE | - |
testcase_69 | RE | - |
testcase_70 | RE | - |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using lint = long long; template <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S), F (*composition)(F, F), F (*id)()> 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; S value; int priority, size; S sum; F lazy; int rev; Node(S value_, int priority_) : left(nullptr), right(nullptr), value(value_), priority(priority_), size(1), sum(value_), lazy(id()), rev(0) {} }; Node *root = nullptr; int cnt(Node *t) { return t ? t->size : 0; } S get_sum(Node *t) { return t ? t->sum : e(); } void update(Node *t) { if (t) { t->size = cnt(t->left) + cnt(t->right) + 1; t->sum = op(op(get_sum(t->left), t->value), get_sum(t->right)); } } void push(Node *t) { if (t && t->rev) { t->rev = false; swap(t->left, t->right); if (t->left) { t->left->rev ^= 1; } if (t->right) { t->right->rev ^= 1; } } all_apply(t->left, t->lazy); all_apply(t->right, t->lazy); t->lazy = id(); } Node *merge(Node *lroot, Node *rroot) { if (!lroot || !rroot) { return lroot ? lroot : rroot; } else if (lroot->priority > rroot->priority) { push(lroot); lroot->right = merge(lroot->right, rroot); update(lroot); return lroot; } else { push(rroot); rroot->left = merge(lroot, rroot->left); update(rroot); return rroot; } } pair<Node *, Node *> split(Node *t, int k) { if (!t) { return {nullptr, nullptr}; } push(t); if (k <= cnt(t->left)) { auto [lroot, rroot] = split(t->left, k); t->left = rroot; update(t); return {lroot, t}; } else { auto [lroot, rroot] = split(t->right, k - cnt(t->left) - 1); t->right = lroot; update(t); return {t, rroot}; } } void all_apply(Node *t, F f) { if (!t) { return; } t->value = mapping(f, t->value); t->sum = mapping(f, t->sum); t->lazy = composition(f, t->lazy); } void dump(Node *t) { if (!t) { return; } push(t); dump(t->left); cout << t->value << " "; dump(t->right); } public: Treap() {} Treap(vector<S> v) { std::reverse(v.begin(), v.end()); for (S &x : v) { insert(0, x); } } Treap(int n) { for (int i = 0; i < n; i++) { insert(0, e()); } } void set(int p, S x) { assert(0 <= p && p < cnt(root)); erase(p); insert(p, x); } void insert(int p, S x) { assert(0 <= p && p <= cnt(root)); auto [lroot, rroot] = split(root, p); root = merge(merge(lroot, new Node(x, xorshift())), rroot); } void erase(int p) { assert(0 <= p && p < cnt(root)); auto [Lroot, rroot] = split(root, p + 1); auto [lroot, mroot] = split(Lroot, p); root = merge(lroot, rroot); } S prod(int l, int r) { assert(0 <= l && l <= r && r <= cnt(root)); if (l == r) { return e(); } auto [Lroot, rroot] = split(root, r); auto [lroot, mroot] = split(Lroot, l); S res = mroot->sum; root = merge(merge(lroot, mroot), rroot); return res; } void apply(int l, int r, F f) { assert(0 <= l && l <= r && r <= cnt(root)); if (l == r) { return; } auto [Lroot, rroot] = split(root, r); auto [lroot, mroot] = split(Lroot, l); all_apply(mroot, f); root = merge(merge(lroot, mroot), rroot); } void reverse(int l, int r) { assert(0 <= l && l <= r && r <= cnt(root)); if (l == r) { return; } auto [Lroot, rroot] = split(root, r); auto [lroot, mroot] = split(Lroot, l); mroot->rev ^= 1; push(mroot); root = merge(merge(lroot, mroot), rroot); } void rotate(int l, int r, int m) { assert(0 <= l && l <= r && r <= cnt(root)); assert(l <= m && m < r); reverse(l, r); reverse(l, l + r - m); reverse(l + r - m, r); } S operator[](int p) { assert(0 <= p && p < cnt(root)); return prod(p, p + 1); } int size() { return cnt(root); } void dump() { dump(root); cout << endl; } }; template <class T> struct Compression { vector<T> a; Compression(vector<T> a_) : a(a_) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); } int size() { return (int)a.size(); } T val(int p) { return a[p]; } int idx(T x) { int res = lower_bound(a.begin(), a.end(), x) - a.begin(); return res; } }; lint op(lint a, lint b) { return a + b; } lint e() { return 0LL; } int main() { int n, q; cin >> n >> q; vector<long long> a(n), d; for (int i = 0; i < n; i++) { cin >> a[i]; d.emplace_back(a[i]); } vector<vector<long long>> qs(q); for (int i = 0; i < q; i++) { int type; cin >> type; if (type == 1) { int k; long long x; cin >> k >> x; k--; qs[i] = {type, k, x}; d.emplace_back(x); } else if (type == 2) { qs[i] = {type}; } else { int k; cin >> k; k--; qs[i] = {type, k}; } } Compression c(d); Treap<lint, op, e, lint, op, op, e> tr(a); fenwick_tree<int> fw(c.size()); for (int i = 0; i < n; i++) { fw.add(c.idx(a[i]), 1); } bool sorted = false; queue<pair<int, long long>> wait; vector<long long> b(n, -1); auto getidx = [&](int k) -> int { if (fw.sum(0, 1) > k) { return 0; } int l = 0, r = (int)c.size() - 1; while (r - l > 1) { int mid = (l + r) / 2; if (fw.sum(0, mid + 1) > k) { r = mid; } else { l = mid; } } return r; }; for (int i = 0; i < q; i++) { int type = qs[i][0]; if (type == 1) { int k = qs[i][1]; long long x = qs[i][2]; wait.push({k, x}); b[k] = x; sorted = false; } else if (type == 2) { while (!wait.empty()) { auto [k, x] = wait.front(); wait.pop(); b[k] = -1; int id = getidx(k); long long px = tr[id]; tr.set(id, x); fw.add(c.idx(px), -1); fw.add(c.idx(x), 1); } sorted = true; } else { int k = qs[i][1]; if (sorted) { int id = getidx(k); cout << c.val(id) << endl; } else { cout << (b[k] == -1 ? tr[k] : b[k]) << endl; } } } }