結果
問題 | No.2809 Sort Query |
ユーザー | dyktr_06 |
提出日時 | 2024-07-13 00:28:25 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 709 ms / 2,000 ms |
コード長 | 9,700 bytes |
コンパイル時間 | 3,030 ms |
コンパイル使用メモリ | 229,468 KB |
実行使用メモリ | 55,516 KB |
最終ジャッジ日時 | 2024-07-13 00:29:08 |
合計ジャッジ時間 | 42,884 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 476 ms
29,340 KB |
testcase_02 | AC | 441 ms
29,944 KB |
testcase_03 | AC | 399 ms
29,172 KB |
testcase_04 | AC | 395 ms
30,392 KB |
testcase_05 | AC | 405 ms
29,176 KB |
testcase_06 | AC | 266 ms
26,104 KB |
testcase_07 | AC | 292 ms
26,228 KB |
testcase_08 | AC | 295 ms
26,100 KB |
testcase_09 | AC | 260 ms
26,228 KB |
testcase_10 | AC | 264 ms
26,840 KB |
testcase_11 | AC | 441 ms
44,252 KB |
testcase_12 | AC | 485 ms
45,096 KB |
testcase_13 | AC | 421 ms
45,336 KB |
testcase_14 | AC | 441 ms
45,200 KB |
testcase_15 | AC | 421 ms
45,732 KB |
testcase_16 | AC | 462 ms
44,644 KB |
testcase_17 | AC | 425 ms
44,256 KB |
testcase_18 | AC | 422 ms
45,720 KB |
testcase_19 | AC | 433 ms
44,036 KB |
testcase_20 | AC | 422 ms
45,468 KB |
testcase_21 | AC | 709 ms
53,868 KB |
testcase_22 | AC | 665 ms
53,668 KB |
testcase_23 | AC | 656 ms
55,516 KB |
testcase_24 | AC | 655 ms
53,648 KB |
testcase_25 | AC | 652 ms
54,268 KB |
testcase_26 | AC | 552 ms
40,940 KB |
testcase_27 | AC | 573 ms
40,912 KB |
testcase_28 | AC | 582 ms
40,680 KB |
testcase_29 | AC | 550 ms
40,840 KB |
testcase_30 | AC | 549 ms
40,808 KB |
testcase_31 | AC | 298 ms
33,796 KB |
testcase_32 | AC | 283 ms
33,788 KB |
testcase_33 | AC | 292 ms
33,808 KB |
testcase_34 | AC | 295 ms
33,800 KB |
testcase_35 | AC | 282 ms
33,788 KB |
testcase_36 | AC | 364 ms
45,216 KB |
testcase_37 | AC | 373 ms
45,132 KB |
testcase_38 | AC | 363 ms
45,120 KB |
testcase_39 | AC | 371 ms
44,352 KB |
testcase_40 | AC | 370 ms
44,836 KB |
testcase_41 | AC | 396 ms
25,004 KB |
testcase_42 | AC | 404 ms
24,592 KB |
testcase_43 | AC | 390 ms
24,764 KB |
testcase_44 | AC | 402 ms
24,748 KB |
testcase_45 | AC | 408 ms
24,404 KB |
testcase_46 | AC | 294 ms
24,284 KB |
testcase_47 | AC | 288 ms
24,148 KB |
testcase_48 | AC | 295 ms
24,276 KB |
testcase_49 | AC | 292 ms
24,272 KB |
testcase_50 | AC | 290 ms
24,420 KB |
testcase_51 | AC | 300 ms
26,976 KB |
testcase_52 | AC | 250 ms
25,504 KB |
testcase_53 | AC | 314 ms
27,488 KB |
testcase_54 | AC | 376 ms
24,408 KB |
testcase_55 | AC | 259 ms
24,404 KB |
testcase_56 | AC | 335 ms
20,860 KB |
testcase_57 | AC | 291 ms
18,008 KB |
testcase_58 | AC | 259 ms
17,640 KB |
testcase_59 | AC | 292 ms
18,400 KB |
testcase_60 | AC | 311 ms
21,044 KB |
testcase_61 | AC | 385 ms
24,668 KB |
testcase_62 | AC | 280 ms
17,568 KB |
testcase_63 | AC | 356 ms
23,324 KB |
testcase_64 | AC | 444 ms
27,124 KB |
testcase_65 | AC | 253 ms
17,048 KB |
testcase_66 | AC | 2 ms
6,944 KB |
testcase_67 | AC | 2 ms
6,940 KB |
testcase_68 | AC | 2 ms
6,940 KB |
testcase_69 | AC | 2 ms
6,940 KB |
testcase_70 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(n) for(int i = 0; i < (int)(n); ++i) #define rep2(i, n) for(int i = 0; i < (int)(n); ++i) #define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i) #define ALL(a) (a).begin(), (a).end() #define Sort(a) (sort((a).begin(), (a).end())) #define RSort(a) (sort((a).rbegin(), (a).rend())) #define UNIQUE(a) (a.erase(unique((a).begin(), (a).end()), (a).end())) typedef long long int ll; typedef unsigned long long ul; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef vector<string> vst; typedef vector<double> vd; typedef vector<long double> vld; typedef pair<long long, long long> P; template<class T> long long sum(const T& a){ return accumulate(a.begin(), a.end(), 0LL); } template<class T> auto min(const T& a){ return *min_element(a.begin(), a.end()); } template<class T> auto max(const T& a){ return *max_element(a.begin(), a.end()); } const long long MINF = 0x7fffffffffff; const long long INF = 0x1fffffffffffffff; const long long MOD = 998244353; const long double EPS = 1e-9; const long double PI = acos(-1); template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p){ is >> p.first >> p.second; return is; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){ os << "(" << p.first << ", " << p.second << ")"; return os; } template<typename T> istream &operator>>(istream &is, vector<T> &v){ for(T &in : v) is >> in; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v){ for(int i = 0; i < (int) v.size(); ++i){ os << v[i] << (i + 1 != (int) v.size() ? " " : ""); } return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &mp){ for(auto &[key, val] : mp){ os << key << ":" << val << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template <typename T> ostream &operator<<(ostream &os, queue<T> q){ while(q.size()){ os << q.front() << " "; q.pop(); } return os; } template <typename T> ostream &operator<<(ostream &os, deque<T> q){ while(q.size()){ os << q.front() << " "; q.pop_front(); } return os; } template <typename T> ostream &operator<<(ostream &os, stack<T> st){ while(st.size()){ os << st.top() << " "; st.pop(); } return os; } template <class T, class Container, class Compare> ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq){ while(pq.size()){ os << pq.top() << " "; pq.pop(); } return os; } template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; } template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; } template<class... T> void in(T&... a){ (cin >> ... >> a); } void out(){ cout << '\n'; } template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } template<class T, class U> void inGraph(vector<vector<T>>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; ++i){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } } 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); } }; void input(){ } void solve(){ ll n, q; in(n, q); vll a; vin(a, n); using T = tuple<ll, ll, ll>; vector<T> query(q); PrioritySet<ll> ps; rep(i, n) ps.add(a[i]); rep(i, q){ ll t; in(t); if(t == 1){ ll k, x; in(k, x); k--; query[i] = {t, k, x}; ps.add(x); } else if(t == 2){ query[i] = {t, -1, -1}; } else{ ll k; in(k); k--; query[i] = {t, k, -1}; } } ps.build(); rep(i, n) ps.insert(a[i]); map<ll, ll> mp; ll sorted = 0; rep(i, q){ ll t, k, x; tie(t, k, x) = query[i]; if(t == 1){ mp[k] = x; }else if(t == 2){ vll erase, add; for(auto [key, val] : mp){ if(sorted){ erase.push_back(ps.kth_small_element(key + 1)); }else{ erase.push_back(a[key]); } add.push_back(val); } for(auto v : erase){ ps.erase(v); } for(auto v : add){ ps.insert(v); } mp.clear(); sorted = 1; }else{ if(mp.count(k)){ out(mp[k]); continue; } if(!sorted){ out(a[k]); }else{ out(ps.kth_small_element(k + 1)); } } } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); input(); solve(); }