結果
問題 | No.2809 Sort Query |
ユーザー | InTheBloom |
提出日時 | 2024-07-13 01:37:46 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,745 bytes |
コンパイル時間 | 2,504 ms |
コンパイル使用メモリ | 124,128 KB |
実行使用メモリ | 41,344 KB |
最終ジャッジ日時 | 2024-07-13 01:38:54 |
合計ジャッジ時間 | 61,658 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 737 ms
32,692 KB |
testcase_12 | AC | 671 ms
34,088 KB |
testcase_13 | WA | - |
testcase_14 | AC | 701 ms
33,876 KB |
testcase_15 | AC | 730 ms
35,512 KB |
testcase_16 | AC | 732 ms
33,712 KB |
testcase_17 | AC | 717 ms
33,104 KB |
testcase_18 | AC | 725 ms
32,972 KB |
testcase_19 | AC | 699 ms
32,804 KB |
testcase_20 | AC | 707 ms
33,908 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 | 565 ms
24,376 KB |
testcase_32 | AC | 547 ms
24,424 KB |
testcase_33 | AC | 568 ms
24,564 KB |
testcase_34 | AC | 548 ms
24,664 KB |
testcase_35 | AC | 573 ms
24,580 KB |
testcase_36 | AC | 649 ms
32,616 KB |
testcase_37 | AC | 663 ms
33,320 KB |
testcase_38 | AC | 641 ms
33,616 KB |
testcase_39 | AC | 673 ms
33,548 KB |
testcase_40 | AC | 691 ms
34,092 KB |
testcase_41 | AC | 873 ms
27,308 KB |
testcase_42 | AC | 905 ms
27,548 KB |
testcase_43 | AC | 914 ms
26,156 KB |
testcase_44 | AC | 903 ms
27,276 KB |
testcase_45 | AC | 904 ms
26,252 KB |
testcase_46 | AC | 657 ms
27,272 KB |
testcase_47 | AC | 699 ms
26,816 KB |
testcase_48 | AC | 661 ms
27,352 KB |
testcase_49 | AC | 664 ms
26,912 KB |
testcase_50 | AC | 702 ms
27,188 KB |
testcase_51 | AC | 508 ms
25,760 KB |
testcase_52 | AC | 547 ms
25,992 KB |
testcase_53 | AC | 497 ms
26,448 KB |
testcase_54 | AC | 517 ms
27,356 KB |
testcase_55 | AC | 496 ms
25,564 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 | 2 ms
6,944 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; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; PrioritySet<ll> ps; for (int i = 0; i < N; i++) ps.add(A[i]); 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]--; ps.add(x[i]); } if (t[i] == 3) { cin >> k[i]; k[i]--; } } ps.build(); for (int i = 0; i < N; i++) ps.insert(A[i]); queue<int> que; vector<bool> changed(N, true); vector<ll> B = A; for (int i = 0; i < N; i++) que.push(i); 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(); que.pop(); ps.erase(A[id]); ps.insert(B[id]); A[id] = B[id]; changed[id] = false; } } if (t[i] == 3) { if (changed[k[i]]) { cout << B[k[i]] << "\n"; } else { cout << ps.kth_small_element(k[i] + 1) << "\n"; } } } }