結果
問題 | No.2809 Sort Query |
ユーザー | InTheBloom |
提出日時 | 2024-07-12 23:52:32 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,689 bytes |
コンパイル時間 | 3,384 ms |
コンパイル使用メモリ | 125,408 KB |
実行使用メモリ | 44,380 KB |
最終ジャッジ日時 | 2024-07-12 23:53:30 |
合計ジャッジ時間 | 57,243 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 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 | 747 ms
36,868 KB |
testcase_12 | AC | 678 ms
37,180 KB |
testcase_13 | WA | - |
testcase_14 | AC | 723 ms
36,980 KB |
testcase_15 | AC | 684 ms
37,160 KB |
testcase_16 | AC | 718 ms
37,984 KB |
testcase_17 | AC | 690 ms
37,676 KB |
testcase_18 | AC | 712 ms
37,720 KB |
testcase_19 | AC | 722 ms
36,832 KB |
testcase_20 | AC | 684 ms
37,196 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,416 KB |
testcase_32 | AC | 538 ms
28,408 KB |
testcase_33 | AC | 532 ms
28,688 KB |
testcase_34 | AC | 536 ms
28,904 KB |
testcase_35 | AC | 527 ms
28,756 KB |
testcase_36 | AC | 630 ms
37,348 KB |
testcase_37 | AC | 649 ms
37,448 KB |
testcase_38 | AC | 622 ms
36,916 KB |
testcase_39 | AC | 648 ms
37,164 KB |
testcase_40 | AC | 623 ms
36,868 KB |
testcase_41 | AC | 688 ms
27,324 KB |
testcase_42 | AC | 674 ms
27,168 KB |
testcase_43 | AC | 709 ms
27,612 KB |
testcase_44 | AC | 698 ms
27,980 KB |
testcase_45 | AC | 678 ms
26,788 KB |
testcase_46 | AC | 589 ms
26,732 KB |
testcase_47 | AC | 574 ms
27,916 KB |
testcase_48 | AC | 569 ms
26,888 KB |
testcase_49 | AC | 580 ms
26,776 KB |
testcase_50 | AC | 566 ms
26,896 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) { changed[k[i]] = true; que.push(k[i]); 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"; } } } }