結果

問題 No.1705 Mode of long array
ユーザー norikamenorikame
提出日時 2021-10-09 12:25:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 3,000 ms
コード長 1,565 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 207,332 KB
実行使用メモリ 8,236 KB
最終ジャッジ日時 2023-10-10 21:51:24
合計ジャッジ時間 12,553 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,352 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 10 ms
4,348 KB
testcase_07 AC 12 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 12 ms
4,352 KB
testcase_12 AC 11 ms
4,348 KB
testcase_13 AC 168 ms
7,856 KB
testcase_14 AC 120 ms
5,440 KB
testcase_15 AC 125 ms
4,352 KB
testcase_16 AC 149 ms
4,348 KB
testcase_17 AC 108 ms
4,352 KB
testcase_18 AC 88 ms
4,348 KB
testcase_19 AC 163 ms
4,436 KB
testcase_20 AC 103 ms
4,516 KB
testcase_21 AC 131 ms
7,772 KB
testcase_22 AC 191 ms
7,764 KB
testcase_23 AC 97 ms
4,348 KB
testcase_24 AC 98 ms
4,352 KB
testcase_25 AC 97 ms
4,352 KB
testcase_26 AC 98 ms
4,352 KB
testcase_27 AC 97 ms
4,348 KB
testcase_28 AC 98 ms
4,348 KB
testcase_29 AC 97 ms
4,352 KB
testcase_30 AC 97 ms
4,352 KB
testcase_31 AC 97 ms
4,352 KB
testcase_32 AC 97 ms
4,352 KB
testcase_33 AC 192 ms
8,236 KB
testcase_34 AC 192 ms
7,944 KB
testcase_35 AC 189 ms
8,120 KB
testcase_36 AC 189 ms
8,052 KB
testcase_37 AC 193 ms
7,980 KB
testcase_38 AC 202 ms
8,068 KB
testcase_39 AC 190 ms
8,032 KB
testcase_40 AC 194 ms
7,980 KB
testcase_41 AC 192 ms
8,092 KB
testcase_42 AC 192 ms
7,996 KB
testcase_43 AC 280 ms
8,008 KB
testcase_44 AC 279 ms
8,032 KB
testcase_45 AC 281 ms
8,048 KB
testcase_46 AC 280 ms
8,040 KB
testcase_47 AC 279 ms
8,060 KB
testcase_48 AC 281 ms
7,976 KB
testcase_49 AC 218 ms
8,064 KB
testcase_50 AC 216 ms
8,000 KB
testcase_51 AC 215 ms
7,932 KB
testcase_52 AC 216 ms
8,036 KB
testcase_53 AC 216 ms
8,036 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, 0 });
		rep(i, n_) update(i+1, 0LL);
	}
	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, 0 };
		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+5);
	rep(i, m) cin >> a[i];
	SegmentTree ta(m+5);
	rep(i, m) ta.update(i+1, a[i]);
	int q;
	cin >> q;
	rep(i, q) {
		int ti, xi;
		ll yi;
		cin >> ti >> xi >> yi;
		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(1, m+1).second;
			cout << res << endl;
		}
	}
	return 0;
}
0