結果

問題 No.1705 Mode of long array
ユーザー ぷらぷら
提出日時 2021-10-08 22:25:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 3,000 ms
コード長 1,479 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 206,376 KB
実行使用メモリ 8,272 KB
最終ジャッジ日時 2023-09-30 10:53:03
合計ジャッジ時間 11,714 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 12 ms
4,376 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 10 ms
4,376 KB
testcase_10 AC 10 ms
4,380 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 147 ms
7,700 KB
testcase_14 AC 108 ms
5,400 KB
testcase_15 AC 113 ms
4,380 KB
testcase_16 AC 133 ms
4,376 KB
testcase_17 AC 96 ms
4,380 KB
testcase_18 AC 79 ms
4,380 KB
testcase_19 AC 147 ms
4,448 KB
testcase_20 AC 91 ms
4,380 KB
testcase_21 AC 115 ms
7,820 KB
testcase_22 AC 170 ms
7,712 KB
testcase_23 AC 89 ms
4,376 KB
testcase_24 AC 89 ms
4,376 KB
testcase_25 AC 92 ms
4,380 KB
testcase_26 AC 90 ms
4,376 KB
testcase_27 AC 88 ms
4,376 KB
testcase_28 AC 89 ms
4,376 KB
testcase_29 AC 89 ms
4,376 KB
testcase_30 AC 89 ms
4,376 KB
testcase_31 AC 90 ms
4,380 KB
testcase_32 AC 89 ms
4,380 KB
testcase_33 AC 160 ms
8,072 KB
testcase_34 AC 161 ms
8,008 KB
testcase_35 AC 160 ms
7,972 KB
testcase_36 AC 160 ms
7,896 KB
testcase_37 AC 162 ms
7,944 KB
testcase_38 AC 159 ms
7,900 KB
testcase_39 AC 162 ms
8,272 KB
testcase_40 AC 160 ms
7,904 KB
testcase_41 AC 160 ms
8,044 KB
testcase_42 AC 166 ms
8,020 KB
testcase_43 AC 254 ms
7,948 KB
testcase_44 AC 253 ms
8,008 KB
testcase_45 AC 252 ms
8,024 KB
testcase_46 AC 254 ms
8,036 KB
testcase_47 AC 255 ms
7,908 KB
testcase_48 AC 251 ms
8,052 KB
testcase_49 AC 186 ms
7,964 KB
testcase_50 AC 186 ms
8,092 KB
testcase_51 AC 189 ms
7,948 KB
testcase_52 AC 186 ms
8,040 KB
testcase_53 AC 187 ms
7,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int inf = 1001001001;

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,{-inf,-inf});
    }
    void update(int x, long long val,int val2) {
        x += (n-1);
        dat[x].first = val;
        dat[x].second = val2;
        while(x > 0) {
            x = (x-1)/2;
            dat[x] = max(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 {-inf,-inf};
        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 max(vl, vr);
    }
    T query(int a,int b) {//[a,b)
        return query(a,b,0,0,n);
    }
};


int main() {
    long long N,M;
    cin >> N >> M;
    vector<long long>a(M);
    SegmentTree<pair<long long,int>>Seg(M);
    for(int i = 0; i < M; i++) {
        cin >> a[i];
        Seg.update(i,a[i],i);
    }
    int Q;
    cin >> Q;
    while (Q--) {
        long long t,x,y;
        cin >> t >> x >> y;
        x--;
        if(t == 1) {
            a[x] += y;
            Seg.update(x,a[x],x);
        }
        if(t == 2) {
            a[x] -= y;
            Seg.update(x,a[x],x);
        }
        if(t == 3) {
            cout << Seg.query(0,M).second+1 << endl;
        }
    }
}
0