結果
問題 | No.2809 Sort Query |
ユーザー | dyktr_06 |
提出日時 | 2024-07-13 00:43:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,402 ms / 2,000 ms |
コード長 | 5,647 bytes |
コンパイル時間 | 3,239 ms |
コンパイル使用メモリ | 231,008 KB |
実行使用メモリ | 69,240 KB |
最終ジャッジ日時 | 2024-07-13 00:45:00 |
合計ジャッジ時間 | 77,636 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 996 ms
57,472 KB |
testcase_02 | AC | 970 ms
58,476 KB |
testcase_03 | AC | 964 ms
57,236 KB |
testcase_04 | AC | 941 ms
59,268 KB |
testcase_05 | AC | 985 ms
57,948 KB |
testcase_06 | AC | 622 ms
54,664 KB |
testcase_07 | AC | 649 ms
53,244 KB |
testcase_08 | AC | 632 ms
53,744 KB |
testcase_09 | AC | 644 ms
52,896 KB |
testcase_10 | AC | 629 ms
54,700 KB |
testcase_11 | AC | 1,029 ms
56,220 KB |
testcase_12 | AC | 1,034 ms
60,612 KB |
testcase_13 | AC | 1,008 ms
59,020 KB |
testcase_14 | AC | 1,064 ms
57,956 KB |
testcase_15 | AC | 997 ms
58,336 KB |
testcase_16 | AC | 980 ms
58,200 KB |
testcase_17 | AC | 1,003 ms
57,204 KB |
testcase_18 | AC | 1,005 ms
58,828 KB |
testcase_19 | AC | 991 ms
59,684 KB |
testcase_20 | AC | 1,001 ms
57,136 KB |
testcase_21 | AC | 1,363 ms
69,240 KB |
testcase_22 | AC | 1,365 ms
68,472 KB |
testcase_23 | AC | 1,357 ms
67,604 KB |
testcase_24 | AC | 1,325 ms
65,040 KB |
testcase_25 | AC | 1,402 ms
68,420 KB |
testcase_26 | AC | 1,286 ms
60,248 KB |
testcase_27 | AC | 1,252 ms
60,176 KB |
testcase_28 | AC | 1,191 ms
58,568 KB |
testcase_29 | AC | 1,223 ms
59,028 KB |
testcase_30 | AC | 1,201 ms
60,520 KB |
testcase_31 | AC | 829 ms
52,588 KB |
testcase_32 | AC | 781 ms
54,092 KB |
testcase_33 | AC | 804 ms
54,912 KB |
testcase_34 | AC | 854 ms
51,672 KB |
testcase_35 | AC | 780 ms
53,472 KB |
testcase_36 | AC | 959 ms
61,864 KB |
testcase_37 | AC | 987 ms
59,496 KB |
testcase_38 | AC | 971 ms
59,968 KB |
testcase_39 | AC | 974 ms
59,780 KB |
testcase_40 | AC | 928 ms
59,480 KB |
testcase_41 | AC | 987 ms
54,816 KB |
testcase_42 | AC | 1,006 ms
56,444 KB |
testcase_43 | AC | 982 ms
54,564 KB |
testcase_44 | AC | 990 ms
55,276 KB |
testcase_45 | AC | 989 ms
55,164 KB |
testcase_46 | AC | 782 ms
54,380 KB |
testcase_47 | AC | 775 ms
54,468 KB |
testcase_48 | AC | 805 ms
56,540 KB |
testcase_49 | AC | 814 ms
53,984 KB |
testcase_50 | AC | 893 ms
54,196 KB |
testcase_51 | AC | 1,051 ms
45,408 KB |
testcase_52 | AC | 889 ms
43,048 KB |
testcase_53 | AC | 946 ms
43,484 KB |
testcase_54 | AC | 1,014 ms
46,368 KB |
testcase_55 | AC | 938 ms
43,088 KB |
testcase_56 | AC | 769 ms
36,240 KB |
testcase_57 | AC | 605 ms
29,060 KB |
testcase_58 | AC | 559 ms
30,472 KB |
testcase_59 | AC | 587 ms
27,596 KB |
testcase_60 | AC | 760 ms
42,176 KB |
testcase_61 | AC | 967 ms
53,552 KB |
testcase_62 | AC | 595 ms
30,472 KB |
testcase_63 | AC | 761 ms
38,160 KB |
testcase_64 | AC | 1,073 ms
54,168 KB |
testcase_65 | AC | 686 ms
34,560 KB |
testcase_66 | AC | 3 ms
6,940 KB |
testcase_67 | AC | 3 ms
6,944 KB |
testcase_68 | AC | 4 ms
6,940 KB |
testcase_69 | AC | 3 ms
6,940 KB |
testcase_70 | AC | 2 ms
6,944 KB |
ソースコード
#define PROBLEM "https://yukicoder.me/problems/no/2809" #include <bits/stdc++.h> using namespace std; 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<long long> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } using T = tuple<long long, long long, long long>; vector<T> query(q); PrioritySet<long long> ps; for(auto v : a) ps.add(v); for(int i = 0; i < q; i++){ int t; cin >> t; if(t == 1){ int k; long long x; cin >> k >> x; k--; query[i] = {t, k, x}; ps.add(x); } else if(t == 2){ query[i] = {t, -1, -1}; } else{ int k; cin >> k; k--; query[i] = {t, k, -1}; } } ps.build(); map<int, long long> mp; for(int i = 0; i < n; i++){ ps.insert(a[i]); mp[i] = a[i]; } for(int i = 0; i < q; i++){ long long t, k, x; tie(t, k, x) = query[i]; if(t == 1){ mp[k] = x; } else if(t == 2){ vector<long long> erase, add; for(auto [key, val] : mp){ erase.push_back(ps.kth_small_element(key + 1)); add.push_back(val); } for(auto v : erase){ ps.erase(v); } for(auto v : add){ ps.insert(v); } mp.clear(); } else{ if(mp.count(k)){ cout << mp[k] << '\n'; continue; } cout << ps.kth_small_element(k + 1) << '\n'; } } }