結果
問題 | No.2809 Sort Query |
ユーザー | kwm_t |
提出日時 | 2024-07-13 11:08:37 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 799 ms / 2,000 ms |
コード長 | 3,265 bytes |
コンパイル時間 | 6,262 ms |
コンパイル使用メモリ | 321,832 KB |
実行使用メモリ | 34,216 KB |
最終ジャッジ日時 | 2024-07-13 11:09:26 |
合計ジャッジ時間 | 47,301 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 473 ms
31,732 KB |
testcase_02 | AC | 450 ms
32,732 KB |
testcase_03 | AC | 476 ms
32,188 KB |
testcase_04 | AC | 453 ms
31,984 KB |
testcase_05 | AC | 445 ms
31,560 KB |
testcase_06 | AC | 371 ms
30,988 KB |
testcase_07 | AC | 333 ms
30,816 KB |
testcase_08 | AC | 333 ms
30,788 KB |
testcase_09 | AC | 333 ms
30,720 KB |
testcase_10 | AC | 331 ms
30,296 KB |
testcase_11 | AC | 222 ms
31,408 KB |
testcase_12 | AC | 215 ms
31,292 KB |
testcase_13 | AC | 224 ms
31,792 KB |
testcase_14 | AC | 224 ms
31,912 KB |
testcase_15 | AC | 223 ms
31,816 KB |
testcase_16 | AC | 225 ms
32,052 KB |
testcase_17 | AC | 224 ms
31,788 KB |
testcase_18 | AC | 222 ms
31,004 KB |
testcase_19 | AC | 224 ms
31,484 KB |
testcase_20 | AC | 220 ms
31,492 KB |
testcase_21 | AC | 412 ms
33,256 KB |
testcase_22 | AC | 414 ms
33,344 KB |
testcase_23 | AC | 410 ms
33,340 KB |
testcase_24 | AC | 414 ms
34,216 KB |
testcase_25 | AC | 420 ms
33,416 KB |
testcase_26 | AC | 584 ms
32,720 KB |
testcase_27 | AC | 588 ms
32,064 KB |
testcase_28 | AC | 578 ms
32,092 KB |
testcase_29 | AC | 576 ms
32,572 KB |
testcase_30 | AC | 573 ms
32,620 KB |
testcase_31 | AC | 366 ms
31,060 KB |
testcase_32 | AC | 368 ms
31,000 KB |
testcase_33 | AC | 366 ms
30,412 KB |
testcase_34 | AC | 363 ms
31,140 KB |
testcase_35 | AC | 365 ms
30,344 KB |
testcase_36 | AC | 187 ms
31,240 KB |
testcase_37 | AC | 187 ms
32,500 KB |
testcase_38 | AC | 188 ms
30,972 KB |
testcase_39 | AC | 188 ms
30,864 KB |
testcase_40 | AC | 190 ms
31,816 KB |
testcase_41 | AC | 778 ms
26,316 KB |
testcase_42 | AC | 768 ms
27,024 KB |
testcase_43 | AC | 799 ms
26,032 KB |
testcase_44 | AC | 792 ms
26,436 KB |
testcase_45 | AC | 760 ms
26,360 KB |
testcase_46 | AC | 718 ms
26,572 KB |
testcase_47 | AC | 745 ms
26,004 KB |
testcase_48 | AC | 723 ms
25,796 KB |
testcase_49 | AC | 725 ms
26,700 KB |
testcase_50 | AC | 736 ms
25,720 KB |
testcase_51 | AC | 735 ms
18,364 KB |
testcase_52 | AC | 582 ms
18,492 KB |
testcase_53 | AC | 616 ms
18,368 KB |
testcase_54 | AC | 578 ms
18,368 KB |
testcase_55 | AC | 610 ms
18,368 KB |
testcase_56 | AC | 348 ms
20,968 KB |
testcase_57 | AC | 326 ms
14,904 KB |
testcase_58 | AC | 267 ms
18,160 KB |
testcase_59 | AC | 314 ms
15,064 KB |
testcase_60 | AC | 283 ms
21,580 KB |
testcase_61 | AC | 371 ms
29,356 KB |
testcase_62 | AC | 283 ms
18,736 KB |
testcase_63 | AC | 368 ms
20,836 KB |
testcase_64 | AC | 442 ms
31,488 KB |
testcase_65 | AC | 229 ms
19,532 KB |
testcase_66 | AC | 2 ms
6,940 KB |
testcase_67 | AC | 2 ms
6,940 KB |
testcase_68 | AC | 2 ms
6,940 KB |
testcase_69 | AC | 2 ms
6,944 KB |
testcase_70 | AC | 2 ms
6,944 KB |
コンパイルメッセージ
In constructor 'FenwickTree::FenwickTree(int)', inlined from 'int main()' at main.cpp:77:29: main.cpp:25:17: warning: 'bit.FenwickTree::size' may be used uninitialized [-Wmaybe-uninitialized] 25 | size += sz; | ^~~~ main.cpp: In function 'int main()': main.cpp:77:21: note: 'bit' declared here 77 | FenwickTree bit(comp.size()); | ^~~
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } struct FenwickTree { vector<int> tree; int size; int start; FenwickTree(int sz) { size += sz; tree.resize(size + 1); start = 0; while ((1 << (start + 1)) <= size)start++; } void add(int pos, int val) { pos++; while (pos <= size) { tree[pos] += val; pos += pos & -pos; } } int bisect(int pos) { int now = 0; int val = 0; for (int i = start; i >= 0; i--) { if (now + (1 << i) <= size && val + tree[now + (1 << i)] <= pos) { now += 1 << i; val += tree[now]; } } return now; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector<long long>a(n); rep(i, n)cin >> a[i]; struct Query { int t; int k; long long x; Query(int t = -1, int k = -1, long long x = -1) :t(t), k(k), x(x) {} void output() { std::cout << t << " " << k << " " << x << endl; } }; vector<long long>comp = a; vector<Query>query(q); rep(i, q) { cin >> query[i].t; if (3 == query[i].t) cin >> query[i].k; else if (1 == query[i].t) { cin >> query[i].k >> query[i].x; comp.push_back(query[i].x); } } sort(all(comp)); comp.erase(unique(all(comp)), comp.end()); //fenwick_tree<int> bit(comp.size()); FenwickTree bit(comp.size()); rep(i, q) { if (1 == query[i].t) { query[i].x = lower_bound(all(comp), query[i].x) - comp.begin(); } } vector<long long>change(n, -1); vector<pair<long long, long long>>chq; vector<int>upd; rep(i, n) { a[i] = lower_bound(all(comp), a[i]) - comp.begin(); change[i] = a[i]; upd.push_back(i); } bit.add(0, n); auto f = [&](int x)->int { return bit.bisect(x); /*int ok = 0; int ng = comp.size(); while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; bool chk = bit.sum(0, mid) <= x; if (chk)ok = mid; else ng = mid; } return ok;*/ }; rep(i, q) { int t = query[i].t; int k = query[i].k; int x = query[i].x; if (1 == t) { change[k - 1] = x; upd.push_back(k - 1); } else if (2 == t) { while (!upd.empty()) { if (-1 != change[upd.back()]) { int pos = f(upd.back()); chq.push_back({ pos,change[upd.back()] }); change[upd.back()] = -1; } upd.pop_back(); } while (!chq.empty()) { auto[f, s] = chq.back(); bit.add(f, -1); bit.add(s, 1); chq.pop_back(); } } else { if (-1 != change[k - 1]) { cout << comp[change[k - 1]] << endl; } else { cout << comp[f(k - 1)] << endl; } } } return 0; }