結果

問題 No.2809 Sort Query
ユーザー pitPpitP
提出日時 2024-07-13 16:14:13
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 834 ms / 2,000 ms
コード長 3,427 bytes
コンパイル時間 8,380 ms
コンパイル使用メモリ 338,000 KB
実行使用メモリ 36,116 KB
最終ジャッジ日時 2024-07-13 16:15:08
合計ジャッジ時間 53,647 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 726 ms
26,972 KB
testcase_02 AC 543 ms
26,656 KB
testcase_03 AC 584 ms
26,616 KB
testcase_04 AC 550 ms
26,004 KB
testcase_05 AC 526 ms
27,328 KB
testcase_06 AC 415 ms
20,616 KB
testcase_07 AC 382 ms
20,248 KB
testcase_08 AC 431 ms
20,176 KB
testcase_09 AC 409 ms
20,156 KB
testcase_10 AC 381 ms
20,552 KB
testcase_11 AC 306 ms
19,316 KB
testcase_12 AC 301 ms
19,404 KB
testcase_13 AC 295 ms
19,308 KB
testcase_14 AC 287 ms
19,312 KB
testcase_15 AC 286 ms
19,304 KB
testcase_16 AC 297 ms
19,324 KB
testcase_17 AC 286 ms
19,300 KB
testcase_18 AC 285 ms
19,308 KB
testcase_19 AC 287 ms
19,316 KB
testcase_20 AC 300 ms
19,360 KB
testcase_21 AC 476 ms
35,872 KB
testcase_22 AC 474 ms
36,116 KB
testcase_23 AC 489 ms
36,012 KB
testcase_24 AC 477 ms
35,976 KB
testcase_25 AC 495 ms
36,000 KB
testcase_26 AC 626 ms
26,388 KB
testcase_27 AC 647 ms
26,608 KB
testcase_28 AC 628 ms
26,516 KB
testcase_29 AC 653 ms
26,396 KB
testcase_30 AC 628 ms
27,328 KB
testcase_31 AC 402 ms
18,648 KB
testcase_32 AC 418 ms
18,332 KB
testcase_33 AC 411 ms
18,492 KB
testcase_34 AC 397 ms
18,452 KB
testcase_35 AC 398 ms
18,236 KB
testcase_36 AC 250 ms
19,304 KB
testcase_37 AC 244 ms
19,388 KB
testcase_38 AC 245 ms
19,304 KB
testcase_39 AC 242 ms
19,328 KB
testcase_40 AC 250 ms
19,296 KB
testcase_41 AC 816 ms
25,312 KB
testcase_42 AC 833 ms
25,220 KB
testcase_43 AC 834 ms
25,348 KB
testcase_44 AC 829 ms
25,348 KB
testcase_45 AC 822 ms
25,220 KB
testcase_46 AC 742 ms
25,348 KB
testcase_47 AC 742 ms
25,348 KB
testcase_48 AC 719 ms
25,216 KB
testcase_49 AC 725 ms
25,348 KB
testcase_50 AC 743 ms
25,348 KB
testcase_51 AC 710 ms
25,220 KB
testcase_52 AC 642 ms
25,220 KB
testcase_53 AC 688 ms
25,220 KB
testcase_54 AC 596 ms
25,220 KB
testcase_55 AC 601 ms
25,220 KB
testcase_56 AC 432 ms
17,292 KB
testcase_57 AC 350 ms
15,288 KB
testcase_58 AC 325 ms
15,284 KB
testcase_59 AC 374 ms
15,572 KB
testcase_60 AC 348 ms
20,580 KB
testcase_61 AC 468 ms
24,612 KB
testcase_62 AC 338 ms
15,600 KB
testcase_63 AC 438 ms
21,640 KB
testcase_64 AC 526 ms
26,172 KB
testcase_65 AC 310 ms
15,188 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
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); }
istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); }
istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } 

typedef long long ll;
typedef vector<vector<int>> Graph;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i,l,r) for (int i = l;i < (int)(r); i++)
#define rep(i,n) for (int i = 0;i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define my_sort(x) sort(x.begin(), x.end())
#define my_max(x) *max_element(all(x))
#define my_min(x) *min_element(all(x))
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;
const int MOD = 998244353;
const int MOD2 = 1e9+7;
const double PI = acos(-1);
vector<int> di = {1,0,-1,0};
vector<int> dj = {0,1,0,-1};

#ifdef LOCAL
#  include <debug_print.hpp>
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

using S = ll;
S op(S a, S b){ return a + b; }
S e(){ return 0ll; }
S target;
bool g(S x){ return x < target; }

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int N, Q; cin >> N >> Q;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> Z = A;

    vector<int> f(Q), k(Q);
    vector<ll> x(Q);
    rep(i, Q){
        cin >> f[i];
        if(f[i] == 1){
            cin >> k[i] >> x[i];
            k[i]--;
            Z.push_back(x[i]);
        }
        if(f[i] == 3){
            cin >> k[i];
            k[i]--;
        }
    }

    sort(all(Z));
    Z.erase(unique(all(Z)), Z.end());
    int L = Z.size();
    segtree<S, op, e> seg(L);
    rep(i, N) {
        A[i] = lower_bound(all(Z), A[i]) - Z.begin();
        seg.set(A[i], seg.get(A[i]) + 1);
    }

    vector<int> lazy;
    vector<int> B(N);
    rep(i, N) {
        B[i] = A[i];
        lazy.push_back(i);
    }

    rep(i, Q){
        // debug(i, lazy, B, f[i]);
        if(f[i] == 1){
            lazy.push_back(k[i]);
            B[k[i]] = lower_bound(all(Z), x[i]) - Z.begin();
        }
        if(f[i] == 2){
            sort(all(lazy));
            lazy.erase(unique(all(lazy)), lazy.end());
            reverse(all(lazy));

            for(auto &l : lazy){
                target = l + 1;
                int r = seg.max_right<g>(0);
                seg.set(r, seg.get(r) - 1);
            }

            for(auto &l : lazy){
                seg.set(B[l], seg.get(B[l]) + 1);
                B[l] = -1;
            }
            lazy.clear();
        }
        if(f[i] == 3){
            if(B[k[i]] != -1){
                cout << Z[B[k[i]]] << endl;
            }
            else{
                target = k[i] + 1;
                int r = seg.max_right<g>(0);
                cout << Z[r] << endl;
            }
        }
    }
}
0