結果

問題 No.2809 Sort Query
ユーザー ぷらぷら
提出日時 2024-07-12 22:02:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,671 ms / 2,000 ms
コード長 5,592 bytes
コンパイル時間 5,176 ms
コンパイル使用メモリ 158,384 KB
実行使用メモリ 48,784 KB
最終ジャッジ日時 2024-07-12 22:04:22
合計ジャッジ時間 83,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1,559 ms
41,836 KB
testcase_02 AC 1,494 ms
41,764 KB
testcase_03 AC 1,426 ms
41,996 KB
testcase_04 AC 1,461 ms
41,868 KB
testcase_05 AC 1,456 ms
41,684 KB
testcase_06 AC 1,004 ms
38,988 KB
testcase_07 AC 996 ms
38,772 KB
testcase_08 AC 1,013 ms
38,792 KB
testcase_09 AC 998 ms
39,076 KB
testcase_10 AC 1,002 ms
38,716 KB
testcase_11 AC 680 ms
39,792 KB
testcase_12 AC 604 ms
39,260 KB
testcase_13 AC 640 ms
40,288 KB
testcase_14 AC 624 ms
39,420 KB
testcase_15 AC 622 ms
40,980 KB
testcase_16 AC 640 ms
39,420 KB
testcase_17 AC 606 ms
40,692 KB
testcase_18 AC 600 ms
39,284 KB
testcase_19 AC 610 ms
39,424 KB
testcase_20 AC 650 ms
39,808 KB
testcase_21 AC 1,503 ms
48,660 KB
testcase_22 AC 1,477 ms
48,264 KB
testcase_23 AC 1,533 ms
48,112 KB
testcase_24 AC 1,474 ms
48,096 KB
testcase_25 AC 1,503 ms
48,784 KB
testcase_26 AC 1,636 ms
42,068 KB
testcase_27 AC 1,601 ms
42,116 KB
testcase_28 AC 1,608 ms
42,136 KB
testcase_29 AC 1,589 ms
42,092 KB
testcase_30 AC 1,629 ms
42,060 KB
testcase_31 AC 414 ms
38,128 KB
testcase_32 AC 427 ms
37,952 KB
testcase_33 AC 419 ms
38,200 KB
testcase_34 AC 446 ms
38,108 KB
testcase_35 AC 414 ms
38,052 KB
testcase_36 AC 518 ms
40,208 KB
testcase_37 AC 486 ms
39,596 KB
testcase_38 AC 507 ms
40,544 KB
testcase_39 AC 504 ms
41,148 KB
testcase_40 AC 515 ms
39,416 KB
testcase_41 AC 1,643 ms
41,340 KB
testcase_42 AC 1,671 ms
41,848 KB
testcase_43 AC 1,652 ms
41,264 KB
testcase_44 AC 1,637 ms
41,632 KB
testcase_45 AC 1,630 ms
40,900 KB
testcase_46 AC 1,618 ms
41,724 KB
testcase_47 AC 1,566 ms
41,848 KB
testcase_48 AC 1,572 ms
41,364 KB
testcase_49 AC 1,565 ms
41,964 KB
testcase_50 AC 1,570 ms
41,044 KB
testcase_51 AC 662 ms
37,760 KB
testcase_52 AC 583 ms
38,276 KB
testcase_53 AC 539 ms
38,408 KB
testcase_54 AC 610 ms
37,856 KB
testcase_55 AC 529 ms
37,756 KB
testcase_56 AC 1,012 ms
27,124 KB
testcase_57 AC 792 ms
22,344 KB
testcase_58 AC 763 ms
23,024 KB
testcase_59 AC 847 ms
21,484 KB
testcase_60 AC 909 ms
31,876 KB
testcase_61 AC 1,182 ms
38,108 KB
testcase_62 AC 785 ms
22,884 KB
testcase_63 AC 1,064 ms
30,460 KB
testcase_64 AC 1,383 ms
39,796 KB
testcase_65 AC 728 ms
25,876 KB
testcase_66 AC 2 ms
6,940 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 <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template<class T> using pq = priority_queue<T,vector<T>,greater<T>>;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }

int dx4[] = {1,0,-1,0};
int dy4[] = {0,1,0,-1};

#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n)-1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a)-1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define setbits(j, n) for(ll iiiii = (n), j = lowbit(iiiii); iiiii; iiiii ^= 1 << j, j = lowbit(iiiii))
#define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(all(v)));)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
#define rng(v, l, r) v.begin() + (l), v.begin() + (r)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))

template <typename T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree() {}
    SegmentTree(int N) {
        n = 1;
        while(n < N) {
            n *= 2;
        }
        dat.resize(2*n-1);
    }
    void update(int x, T val) {
        x += n-1;
        dat[x] += val;
        while(x > 0) {
            x = (x-1)/2;
            dat[x] = dat[2*x+1]+dat[2*x+2];
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return vl+vr;
    }
    T query(int a,int b) {//[a,b)
        return query(a,b,0,0,n);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Q;
    cin >> N >> Q;
    vc<ll>A(N),B;
    rep(i,N) {
        cin >> A[i];
        B.pb(A[i]);
    }
    vc<array<ll,3>>query(Q);
    rep(i,Q) {
        cin >> query[i][0];
        if(query[i][0] == 1) {
            cin >> query[i][1] >> query[i][2];
            query[i][1]--;
            B.pb(query[i][2]);
        }
        if(query[i][0] == 3) {
            cin >> query[i][1];
            query[i][1]--;
        }
    }
    map<int,ll>id;
    rep(i,N) {
        id[i] = A[i];
    }
    B.pb(0);
    UNIQUE(B);
    SegmentTree<int>Seg(si(B));
    rep(i,N) {
        A[i] = 0;
    }
    Seg.update(0,N);
    auto calc = [&](int k) {
        int l = -1,r = si(B)-1;
        while(l+1 < r) {
            int mid = (l+r)/2;
            if(Seg.query(0,mid+1) < k) {
                l = mid;
            }
            else {
                r = mid;
            }
        }
        return B[r];
    };
    rep(i,Q) {
        if(query[i][0] == 1) {
            id[query[i][1]] = query[i][2];
        }
        if(query[i][0] == 2) {
            vc<int>res;
            for(auto i:id) {
                int pos1 = lower_bound(all(B),calc(i.fi+1))-B.begin();
                res.pb(pos1);
            }
            for(auto i:id) {
                int pos2 = lower_bound(all(B),i.se)-B.begin();
                Seg.update(pos2,1);
            }
            for(auto i:res) {
                Seg.update(i,-1);
            }
            id.clear();
        }
        if(query[i][0] == 3) {
            if(id.count(query[i][1])) {
                cout << id[query[i][1]] << "\n";
                continue;
            }
            cout << calc(query[i][1]+1) << "\n";
        }
    }
}
0