結果

問題 No.1705 Mode of long array
ユーザー norikamenorikame
提出日時 2021-10-09 12:08:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,570 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 207,228 KB
実行使用メモリ 8,304 KB
最終ジャッジ日時 2023-10-10 21:50:56
合計ジャッジ時間 13,096 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 10 ms
4,352 KB
testcase_07 AC 12 ms
4,352 KB
testcase_08 AC 12 ms
4,352 KB
testcase_09 AC 11 ms
4,352 KB
testcase_10 AC 10 ms
4,348 KB
testcase_11 AC 11 ms
4,348 KB
testcase_12 AC 10 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 AC 261 ms
7,924 KB
testcase_44 AC 260 ms
7,928 KB
testcase_45 AC 265 ms
8,252 KB
testcase_46 AC 262 ms
8,120 KB
testcase_47 AC 262 ms
7,924 KB
testcase_48 AC 262 ms
7,924 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

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 });
		rep(i, n) update(i, 0LL);
	}
	void update(int k, int 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+1);
	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