結果

問題 No.2809 Sort Query
ユーザー reirei
提出日時 2024-07-12 23:14:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 926 ms / 2,000 ms
コード長 2,290 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 140,108 KB
実行使用メモリ 65,752 KB
最終ジャッジ日時 2024-07-12 23:15:35
合計ジャッジ時間 53,983 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 526 ms
59,820 KB
testcase_02 AC 495 ms
60,188 KB
testcase_03 AC 504 ms
59,892 KB
testcase_04 AC 501 ms
60,532 KB
testcase_05 AC 490 ms
60,112 KB
testcase_06 AC 527 ms
59,936 KB
testcase_07 AC 485 ms
61,040 KB
testcase_08 AC 520 ms
60,152 KB
testcase_09 AC 494 ms
60,036 KB
testcase_10 AC 489 ms
59,780 KB
testcase_11 AC 819 ms
65,752 KB
testcase_12 AC 834 ms
64,164 KB
testcase_13 AC 825 ms
64,192 KB
testcase_14 AC 843 ms
65,364 KB
testcase_15 AC 831 ms
65,584 KB
testcase_16 AC 859 ms
65,092 KB
testcase_17 AC 820 ms
65,052 KB
testcase_18 AC 847 ms
64,856 KB
testcase_19 AC 822 ms
64,892 KB
testcase_20 AC 854 ms
65,064 KB
testcase_21 AC 907 ms
64,828 KB
testcase_22 AC 926 ms
64,188 KB
testcase_23 AC 877 ms
65,400 KB
testcase_24 AC 918 ms
64,828 KB
testcase_25 AC 906 ms
65,184 KB
testcase_26 AC 684 ms
61,184 KB
testcase_27 AC 728 ms
61,516 KB
testcase_28 AC 696 ms
61,872 KB
testcase_29 AC 697 ms
61,868 KB
testcase_30 AC 723 ms
61,284 KB
testcase_31 AC 633 ms
61,164 KB
testcase_32 AC 610 ms
60,948 KB
testcase_33 AC 684 ms
62,272 KB
testcase_34 AC 631 ms
61,556 KB
testcase_35 AC 653 ms
61,512 KB
testcase_36 AC 742 ms
64,240 KB
testcase_37 AC 737 ms
64,356 KB
testcase_38 AC 767 ms
64,452 KB
testcase_39 AC 732 ms
64,512 KB
testcase_40 AC 784 ms
64,116 KB
testcase_41 AC 548 ms
57,288 KB
testcase_42 AC 546 ms
57,428 KB
testcase_43 AC 584 ms
57,352 KB
testcase_44 AC 556 ms
57,284 KB
testcase_45 AC 552 ms
57,696 KB
testcase_46 AC 474 ms
58,304 KB
testcase_47 AC 449 ms
58,556 KB
testcase_48 AC 471 ms
58,160 KB
testcase_49 AC 452 ms
58,880 KB
testcase_50 AC 473 ms
58,224 KB
testcase_51 AC 565 ms
58,516 KB
testcase_52 AC 580 ms
57,280 KB
testcase_53 AC 466 ms
58,292 KB
testcase_54 AC 503 ms
57,856 KB
testcase_55 AC 453 ms
57,848 KB
testcase_56 AC 371 ms
37,828 KB
testcase_57 AC 294 ms
32,384 KB
testcase_58 AC 328 ms
32,920 KB
testcase_59 AC 288 ms
30,920 KB
testcase_60 AC 400 ms
48,800 KB
testcase_61 AC 520 ms
56,740 KB
testcase_62 AC 294 ms
32,424 KB
testcase_63 AC 432 ms
38,512 KB
testcase_64 AC 551 ms
57,024 KB
testcase_65 AC 345 ms
36,572 KB
testcase_66 AC 2 ms
6,944 KB
testcase_67 AC 2 ms
6,940 KB
testcase_68 AC 2 ms
6,944 KB
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <atcoder/lazysegtree.hpp>
#include <atcoder/segtree.hpp>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i8 = int8_t;
using i32 = int;
using i64 = long long;
// using i128 = __int128;
using u64 = unsigned long long;
using ll = long long;

void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}

i64 pow(i64 j, i64 n) {
  i64 res = 1;
  while (n > 0) {
    if (n & 1)
      res *= j;
    j *= j;
    n >>= 1;
  }
  return res;
}

i64 op(i64 a, i64 b) { return a + b; }
i64 e() { return 0; }

i64 n, q;
void _main() {
  cin >> n >> q;
  vector<pair<i64, i64>> vs;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++) {
    cin >> a[i];
    vs.push_back({a[i], i});
    vs.push_back({0, i});
  }
  vector<tuple<i64, i64, i64>> query(q);
  for (i64 i = 0; i < q; i++) {
    i64 op, k, x;
    cin >> op;
    if (op == 1) {
      cin >> k >> x;
      vs.push_back({x, n + i});
    } else if (op == 3) {
      cin >> k;
    }
    k--;
    query[i] = {op, k, x};
  }
  sort(vs.begin(), vs.end());
  atcoder::segtree<i64, op, e> seg(vs.size());
  vector<i64> update(vs.size(), 0);
  set<i64> bk;
  for (i64 i = 0; i < n; i++) {
    seg.set(i, 1);
    i64 j = lower_bound(vs.begin(), vs.end(), make_pair(a[i], i)) - vs.begin();
    update[i] = j;
    bk.insert(i);
  }
  for (i64 i = 0; i < q; i++) {
    i64 op = get<0>(query[i]);
    i64 k = get<1>(query[i]);
    i64 x = get<2>(query[i]);
    if (op == 1) {
      i64 j =
          lower_bound(vs.begin(), vs.end(), make_pair(x, n + i)) - vs.begin();
      i64 p = seg.max_right(0, [&](i64 a) { return a <= k; });
      update[p] = j;
      bk.insert(p);
    } else if (op == 2) {
      while (!bk.empty()) {
        i64 j = *bk.begin();
        bk.erase(j);
        seg.set(j, seg.get(j) - 1);
        seg.set(update[j], seg.get(update[j]) + 1);
        update[j] = 0;
      }
    } else {
      i64 p = seg.max_right(0, [&](i64 a) { return a <= k; });
      if (update[p] == 0) {
        cout << vs[p].first << "\n";
      } else {
        cout << vs[update[p]].first << "\n";
      }
    }
  }
}
0