結果

問題 No.1705 Mode of long array
ユーザー abc3abc3
提出日時 2021-10-11 17:03:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 3,000 ms
コード長 1,881 bytes
コンパイル時間 4,035 ms
コンパイル使用メモリ 205,936 KB
実行使用メモリ 10,444 KB
最終ジャッジ日時 2023-10-14 00:22:34
合計ジャッジ時間 8,964 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 9 ms
4,352 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 7 ms
4,352 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 8 ms
4,352 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 81 ms
9,588 KB
testcase_14 AC 62 ms
6,504 KB
testcase_15 AC 69 ms
4,348 KB
testcase_16 AC 84 ms
4,352 KB
testcase_17 AC 60 ms
4,352 KB
testcase_18 AC 49 ms
4,348 KB
testcase_19 AC 89 ms
5,168 KB
testcase_20 AC 55 ms
4,968 KB
testcase_21 AC 63 ms
9,340 KB
testcase_22 AC 94 ms
10,076 KB
testcase_23 AC 37 ms
4,352 KB
testcase_24 AC 36 ms
4,348 KB
testcase_25 AC 36 ms
4,348 KB
testcase_26 AC 36 ms
4,348 KB
testcase_27 AC 36 ms
4,348 KB
testcase_28 AC 37 ms
4,352 KB
testcase_29 AC 36 ms
4,352 KB
testcase_30 AC 36 ms
4,352 KB
testcase_31 AC 36 ms
4,352 KB
testcase_32 AC 36 ms
4,348 KB
testcase_33 AC 59 ms
10,384 KB
testcase_34 AC 60 ms
10,308 KB
testcase_35 AC 59 ms
10,332 KB
testcase_36 AC 58 ms
10,352 KB
testcase_37 AC 58 ms
10,340 KB
testcase_38 AC 60 ms
10,348 KB
testcase_39 AC 61 ms
10,392 KB
testcase_40 AC 60 ms
10,344 KB
testcase_41 AC 59 ms
10,360 KB
testcase_42 AC 61 ms
10,300 KB
testcase_43 AC 177 ms
10,444 KB
testcase_44 AC 180 ms
10,396 KB
testcase_45 AC 176 ms
10,300 KB
testcase_46 AC 177 ms
10,340 KB
testcase_47 AC 180 ms
10,296 KB
testcase_48 AC 176 ms
10,400 KB
testcase_49 AC 88 ms
10,308 KB
testcase_50 AC 87 ms
10,308 KB
testcase_51 AC 86 ms
10,328 KB
testcase_52 AC 85 ms
10,392 KB
testcase_53 AC 88 ms
10,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    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; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=1e9+7;
    
	struct SegmentTree {
	private:
		int n;
		vector<P> node;
	
	public:
		SegmentTree(vector<P> v) {
			int sz = v.size();
			n = 1; while(n < sz) n *= 2;
			node.resize(2*n-1);
			for(int i=0; i<sz; i++) node[i+n-1] = v[i];
			for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]);
		}
	
		void add(int x, ll val) {
			x += (n - 1);
			node[x].first += val;
			while(x > 0) {
				x = (x - 1) / 2;
				node[x] = max(node[2*x+1], node[2*x+2]);
			}
		}
	
		P getmax(int a, int b, int k=0, int l=0, int r=-1) {
			if(r < 0) r = n;
			if(r <= a || b <= l) return {0,0};
			if(a <= l && r <= b) return node[k];
	
			auto vl = getmax(a, b, 2*k+1, l, (l+r)/2);
			auto vr = getmax(a, b, 2*k+2, (l+r)/2, r);
			return max(vl, vr);
		}
	};

    void solve(){
        ll n,m;
		cin>>n>>m;
		vector<P>a(m);
		rep(i,m){
			cin>>a[i].first;
			a[i].second=i+1;
		}
		int q;
		cin>>q;
		SegmentTree seg(a);
		rep(i,q){
			ll t,x,y;
			cin>>t>>x>>y;
			x--;
			if(t==1){
                seg.add(x,y);
			}
			else if(t==2){
                seg.add(x,-y);
			}
			else{
                auto p=seg.getmax(0,m+1);
                cout<<p.second<<endl;
			}
		}
    } 
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve();  

        return 0;
    }
0