結果
問題 | No.2809 Sort Query |
ユーザー | InTheBloom |
提出日時 | 2024-07-12 23:56:27 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,709 bytes |
コンパイル時間 | 2,575 ms |
コンパイル使用メモリ | 124,888 KB |
実行使用メモリ | 44,412 KB |
最終ジャッジ日時 | 2024-07-12 23:57:33 |
合計ジャッジ時間 | 54,076 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 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 | 695 ms
37,140 KB |
testcase_12 | AC | 644 ms
37,232 KB |
testcase_13 | WA | - |
testcase_14 | AC | 681 ms
37,676 KB |
testcase_15 | AC | 675 ms
36,888 KB |
testcase_16 | AC | 674 ms
36,668 KB |
testcase_17 | AC | 681 ms
37,508 KB |
testcase_18 | AC | 701 ms
37,320 KB |
testcase_19 | AC | 675 ms
37,172 KB |
testcase_20 | AC | 681 ms
37,280 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 | 531 ms
28,492 KB |
testcase_32 | AC | 530 ms
28,680 KB |
testcase_33 | AC | 531 ms
28,816 KB |
testcase_34 | AC | 531 ms
28,700 KB |
testcase_35 | AC | 555 ms
28,536 KB |
testcase_36 | AC | 629 ms
38,544 KB |
testcase_37 | AC | 630 ms
36,808 KB |
testcase_38 | AC | 624 ms
37,424 KB |
testcase_39 | AC | 625 ms
37,688 KB |
testcase_40 | AC | 626 ms
37,012 KB |
testcase_41 | AC | 691 ms
27,420 KB |
testcase_42 | AC | 666 ms
26,920 KB |
testcase_43 | AC | 687 ms
28,156 KB |
testcase_44 | AC | 697 ms
27,132 KB |
testcase_45 | AC | 662 ms
28,260 KB |
testcase_46 | AC | 597 ms
27,732 KB |
testcase_47 | AC | 554 ms
26,816 KB |
testcase_48 | AC | 557 ms
26,952 KB |
testcase_49 | AC | 559 ms
27,132 KB |
testcase_50 | AC | 554 ms
27,064 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 | 2 ms
6,940 KB |
ソースコード
#include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; using ll = long long; constexpr int iINF = 1'000'000'000; constexpr ll llINF = 1'000'000'000'000'000'000; // https://github.com/dyktr06/kyopro_library/blob/main/lib/data_structure/priority_set.hpp // thank you very much dyktr_06 template <typename T> struct PrioritySet{ struct compress{ vector<T> sorted, compressed; compress(){} void init(const vector<T> &vec){ int n = vec.size(); compressed.resize(n); for(T x : vec){ sorted.emplace_back(x); } sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end()); for(int i = 0; i < n; ++i){ compressed[i] = lower_bound(sorted.begin(), sorted.end(), vec[i]) - sorted.begin(); } } int get(const T &x) const{ return lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin(); } T inv(const T &x) const{ return sorted[x]; } size_t size() const{ return sorted.size(); } vector<T> getCompressed() const{ return compressed; } }; struct BinaryIndexedTree{ int N; vector<T> BIT; BinaryIndexedTree() {} void init(int size){ N = size; BIT.assign(N + 1, 0); } T get(int i){ return sum(i + 1) - sum(i); } void add(int i, T x){ i++; while(i <= N){ BIT[i] += x; i += i & -i; } } T sum(int i) const { T ans = 0; while(i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } T sum(int L, int R) const { return sum(R) - sum(L); } int lower_bound(T x) const { if(x <= 0){ return 0; } else{ int v = 0, r = 1; while(r < N) r = r << 1; for(int len = r; len > 0; len = len >> 1){ if(v + len < N && BIT[v + len] < x){ x -= BIT[v + len]; v += len; } } return v; } } int upper_bound(T x) const { if(x < 0){ return 0; } else{ int v = 0, r = 1; while(r <= N) r = r << 1; for(int len = r; len > 0; len = len >> 1){ if(v + len <= N && BIT[v + len] <= x){ x -= BIT[v + len]; v += len; } } return v; } } T operator [](int i) const { return sum(i, i + 1); } }; vector<T> a; compress comp; BinaryIndexedTree cnt, val; PrioritySet(){ } void add(T x){ a.push_back(x); } void build(){ comp.init(a); cnt.init(comp.size()); val.init(comp.size()); } T size(){ return cnt.sum((int) comp.size()); } void insert(T x, T count = 1){ cnt.add(comp.get(x), count); val.add(comp.get(x), count * x); } void erase(T x, T count = 1){ T idx = comp.get(x); if(cnt.get(idx) < count){ count = cnt.get(idx); } cnt.add(idx, -count); val.add(idx, -count * x); } // 1-indexed T kth_small_element(T k){ T idx = cnt.lower_bound(k); return comp.inv(idx); } T kth_large_element(T k){ T rev_k = size() - k + 1; return kth_small_element(rev_k); } // 1-indexed T kth_small_sum(T k){ if(size() < k){ return val.sum((int) comp.size()); } T idx = cnt.lower_bound(k); T sum = val.sum(idx); sum += comp.inv(idx) * (k - cnt.sum(idx)); return sum; } T kth_large_sum(T k){ if(size() < k){ return val.sum((int) comp.size()); } T rev_k = size() - k; return val.sum((int) comp.size()) - kth_small_sum(rev_k); } }; int main () { int N, Q; cin >> N >> Q; PrioritySet<ll> ps; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<ll> possible = A; vector<int> t(Q), k(Q); vector<ll> x(Q); for (int i = 0; i < Q; i++) { cin >> t[i]; if (t[i] == 1) { cin >> k[i] >> x[i]; k[i]--; possible.push_back(x[i]); } if (t[i] == 3) { cin >> k[i]; k[i]--; } } ps.a = possible; ps.build(); for (int i = 0; i < N; i++) ps.insert(A[i]); queue<int> que; vector<bool> changed(N); vector<ll> B(N); for (int i = 0; i < Q; i++) { if (t[i] == 1) { if (!changed[k[i]]) que.push(k[i]); changed[k[i]] = true; B[k[i]] = x[i]; } if (t[i] == 2) { while (!que.empty()) { int id = que.front(); ps.erase(A[id]); ps.insert(B[id]); A[id] = B[id]; changed[id] = false; que.pop(); } } if (t[i] == 3) { if (changed[k[i]]) { cout << B[k[i]] << "\n"; } else { cout << ps.kth_small_element(k[i] + 1) << "\n"; } } } }