結果

問題 No.1705 Mode of long array
ユーザー norikamenorikame
提出日時 2021-10-09 12:28:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 3,000 ms
コード長 1,546 bytes
コンパイル時間 2,581 ms
コンパイル使用メモリ 206,956 KB
実行使用メモリ 8,208 KB
最終ジャッジ日時 2023-10-10 21:51:49
合計ジャッジ時間 11,586 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 10 ms
4,352 KB
testcase_07 AC 13 ms
4,348 KB
testcase_08 AC 12 ms
4,348 KB
testcase_09 AC 11 ms
4,348 KB
testcase_10 AC 10 ms
4,352 KB
testcase_11 AC 11 ms
4,348 KB
testcase_12 AC 11 ms
4,352 KB
testcase_13 AC 160 ms
7,720 KB
testcase_14 AC 116 ms
5,392 KB
testcase_15 AC 122 ms
4,348 KB
testcase_16 AC 145 ms
4,348 KB
testcase_17 AC 105 ms
4,352 KB
testcase_18 AC 85 ms
4,348 KB
testcase_19 AC 159 ms
4,416 KB
testcase_20 AC 98 ms
4,348 KB
testcase_21 AC 123 ms
7,852 KB
testcase_22 AC 184 ms
7,768 KB
testcase_23 AC 94 ms
4,352 KB
testcase_24 AC 96 ms
4,352 KB
testcase_25 AC 96 ms
4,352 KB
testcase_26 AC 95 ms
4,348 KB
testcase_27 AC 95 ms
4,352 KB
testcase_28 AC 96 ms
4,352 KB
testcase_29 AC 96 ms
4,348 KB
testcase_30 AC 95 ms
4,348 KB
testcase_31 AC 96 ms
4,348 KB
testcase_32 AC 96 ms
4,352 KB
testcase_33 AC 181 ms
8,040 KB
testcase_34 AC 180 ms
8,116 KB
testcase_35 AC 181 ms
7,900 KB
testcase_36 AC 180 ms
8,092 KB
testcase_37 AC 182 ms
8,044 KB
testcase_38 AC 180 ms
8,124 KB
testcase_39 AC 180 ms
8,032 KB
testcase_40 AC 183 ms
8,004 KB
testcase_41 AC 183 ms
7,964 KB
testcase_42 AC 185 ms
7,992 KB
testcase_43 AC 258 ms
8,208 KB
testcase_44 AC 258 ms
8,096 KB
testcase_45 AC 254 ms
8,092 KB
testcase_46 AC 255 ms
7,916 KB
testcase_47 AC 256 ms
8,040 KB
testcase_48 AC 257 ms
7,988 KB
testcase_49 AC 208 ms
8,044 KB
testcase_50 AC 205 ms
7,936 KB
testcase_51 AC 205 ms
7,900 KB
testcase_52 AC 205 ms
7,940 KB
testcase_53 AC 206 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

// 

struct SegmentTree {
	int n;
	vector<pair<ll, int>> dat;
	SegmentTree() { init(1); }
	SegmentTree(int n_) { init(n_); }
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat = vector<pair<ll, int>>(2*n-1, { 0LL, -1 });
	}
	void update(int k, ll a) {
		int tk = k;
		k += n-1;
		dat[k] = { a, tk };
		while (k > 0) {
			k = (k-1) / 2;
			dat[k] = max(dat[k*2+1], dat[k*2+2]);
		}
	}
	pair<ll, int> query(int a, int b, int k=0, int l=0, int r=-1) {
		if (r == -1) { r = n; k = 0; l = 0; }
		if (r<=a || b<=l) return { 0LL, -1 };
		if (a<=l && r<=b) return dat[k];
		else {
			auto vl = query(a, b, k*2+1, l, (l+r)/2);
			auto vr = query(a, b, k*2+2, (l+r)/2, r);
			return max(vl, vr);
		}
	}
};

int main() {
	ll n;
	int m;
	cin >> n >> m;
	vector<ll> a(m);
	rep(i, m) cin >> a[i];
	SegmentTree ta(m+2);
	rep(i, m) ta.update(i, a[i]);
	int q;
	cin >> q;
	rep(i, q) {
		int ti, xi;
		ll yi;
		cin >> ti >> xi >> yi;
		--xi;
		if (ti == 1) {
			ll pyi = ta.query(xi, xi+1).first;
			ta.update(xi, pyi+yi);
		}
		else if (ti == 2) {
			ll pyi = ta.query(xi, xi+1).first;
			ta.update(xi, pyi-yi);
		}
		else {
			int res = ta.query(0, m).second + 1;
			cout << res << endl;
		}
	}
	return 0;
}
0