結果

問題 No.1705 Mode of long array
ユーザー asaringoasaringo
提出日時 2021-10-09 00:21:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 382 ms / 3,000 ms
コード長 1,948 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 182,076 KB
実行使用メモリ 8,500 KB
最終ジャッジ日時 2023-09-30 15:00:08
合計ジャッジ時間 12,203 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,520 KB
testcase_01 AC 3 ms
7,520 KB
testcase_02 AC 3 ms
7,512 KB
testcase_03 AC 6 ms
7,596 KB
testcase_04 AC 5 ms
7,528 KB
testcase_05 AC 7 ms
7,568 KB
testcase_06 AC 14 ms
7,608 KB
testcase_07 AC 18 ms
7,464 KB
testcase_08 AC 17 ms
7,456 KB
testcase_09 AC 14 ms
7,500 KB
testcase_10 AC 14 ms
7,484 KB
testcase_11 AC 15 ms
7,452 KB
testcase_12 AC 15 ms
7,568 KB
testcase_13 AC 169 ms
8,080 KB
testcase_14 AC 127 ms
7,892 KB
testcase_15 AC 142 ms
7,636 KB
testcase_16 AC 167 ms
7,568 KB
testcase_17 AC 122 ms
7,560 KB
testcase_18 AC 99 ms
7,540 KB
testcase_19 AC 179 ms
7,792 KB
testcase_20 AC 112 ms
7,636 KB
testcase_21 AC 133 ms
8,016 KB
testcase_22 AC 195 ms
8,252 KB
testcase_23 AC 90 ms
7,448 KB
testcase_24 AC 90 ms
7,596 KB
testcase_25 AC 91 ms
7,460 KB
testcase_26 AC 90 ms
7,456 KB
testcase_27 AC 90 ms
7,468 KB
testcase_28 AC 90 ms
7,600 KB
testcase_29 AC 90 ms
7,444 KB
testcase_30 AC 91 ms
7,704 KB
testcase_31 AC 90 ms
7,460 KB
testcase_32 AC 91 ms
7,500 KB
testcase_33 AC 152 ms
8,268 KB
testcase_34 AC 152 ms
8,248 KB
testcase_35 AC 153 ms
8,320 KB
testcase_36 AC 153 ms
8,244 KB
testcase_37 AC 152 ms
8,264 KB
testcase_38 AC 153 ms
8,316 KB
testcase_39 AC 153 ms
8,300 KB
testcase_40 AC 152 ms
8,304 KB
testcase_41 AC 152 ms
8,284 KB
testcase_42 AC 152 ms
8,496 KB
testcase_43 AC 379 ms
8,252 KB
testcase_44 AC 380 ms
8,264 KB
testcase_45 AC 382 ms
8,268 KB
testcase_46 AC 380 ms
8,268 KB
testcase_47 AC 382 ms
8,244 KB
testcase_48 AC 380 ms
8,500 KB
testcase_49 AC 198 ms
8,244 KB
testcase_50 AC 199 ms
8,344 KB
testcase_51 AC 197 ms
8,240 KB
testcase_52 AC 197 ms
8,268 KB
testcase_53 AC 199 ms
8,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair<int,int> P ;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)

const int MAX_N = 1 << 18 ;

template<typename T>
struct SegmentTree{
    int n ;
    T dat[2 * MAX_N - 1] ;
    SegmentTree(int n_){
        n = 1 ;
        while(n < n_) n *= 2 ;
        memset(dat,0,sizeof(dat)) ;
    }
    void add(int k , T x){
        k += n - 1 ;
        dat[k] += x ;
        while(k > 0){
            k = (k - 1) / 2 ;
            dat[k] = max(dat[2*k+1],dat[2*k+2]) ;
        }
    }
    T sub_query(int a , int b , int k , int l , int r){
        if(r <= a || b <= l) return -1e18 ;
        if(a <= l && r <= b) return dat[k] ;
        T lef = sub_query(a,b,2*k+1,l,(l+r)/2) ;
        T rig = sub_query(a,b,2*k+2,(l+r)/2,r) ;
        return max(lef,rig) ;
    }
    T query(int a , int b){
        return sub_query(a,b,0,0,n) ;
    }
    T solve(){
        int lef = 0 , rig = n ;
        while(rig - lef > 1){
            ll mid = (lef + rig) / 2 ;
            if(query(lef,mid) <= query(mid,rig)) lef = mid ;
            else rig = mid ;
        }
        return lef ;
    }
};

ll n , m , q ;

ll A[101010] , B[101010] , C[101010] ;
unordered_map<int,int> mp ;

int main(){
    cin >> n >> m ;
    SegmentTree<ll> SegTree(202020) ;
    rep(i,m) cin >> A[i] ;
    rep(i,m) SegTree.add(i,A[i]) ;
    cin >> q ;
    int id = m ;
    rep(i,q){
        ll t , x , y ;
        cin >> t >> x >> y ;
        x-- ;
        if(x >= m){
            mp[id] = x ;
            mp[x] = id ;
            x = id ;
            id++ ;
        }
        if(t == 1){
            SegTree.add(x,y) ;
        }
        if(t == 2){
            SegTree.add(x,-y) ;
        }
        if(t == 3){
            ll res = SegTree.solve() ;
            if(res >= m) res = mp[res] ;
            else res++ ;
            cout << res << endl ;
        }
    }
}
0