結果

問題 No.1705 Mode of long array
ユーザー abc3abc3
提出日時 2021-10-11 17:01:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,884 bytes
コンパイル時間 4,707 ms
コンパイル使用メモリ 205,628 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-14 00:19:45
合計ジャッジ時間 6,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 7 ms
4,352 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

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<int,int>;
    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(){
        int 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