結果

問題 No.1705 Mode of long array
ユーザー 小野寺健小野寺健
提出日時 2021-11-30 13:10:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,750 ms / 3,000 ms
コード長 1,755 bytes
コンパイル時間 4,332 ms
コンパイル使用メモリ 74,752 KB
実行使用メモリ 85,588 KB
最終ジャッジ日時 2023-09-16 05:54:11
合計ジャッジ時間 66,996 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
56,156 KB
testcase_01 AC 136 ms
55,904 KB
testcase_02 AC 127 ms
55,820 KB
testcase_03 AC 270 ms
59,816 KB
testcase_04 AC 253 ms
59,664 KB
testcase_05 AC 283 ms
60,472 KB
testcase_06 AC 370 ms
60,104 KB
testcase_07 AC 406 ms
61,028 KB
testcase_08 AC 419 ms
60,984 KB
testcase_09 AC 403 ms
62,408 KB
testcase_10 AC 400 ms
60,512 KB
testcase_11 AC 400 ms
60,556 KB
testcase_12 AC 418 ms
62,212 KB
testcase_13 AC 1,373 ms
84,488 KB
testcase_14 AC 1,197 ms
72,856 KB
testcase_15 AC 1,145 ms
67,476 KB
testcase_16 AC 1,269 ms
73,312 KB
testcase_17 AC 1,091 ms
67,244 KB
testcase_18 AC 981 ms
67,336 KB
testcase_19 AC 1,355 ms
75,776 KB
testcase_20 AC 1,062 ms
71,380 KB
testcase_21 AC 1,204 ms
81,232 KB
testcase_22 AC 1,515 ms
85,588 KB
testcase_23 AC 954 ms
64,896 KB
testcase_24 AC 938 ms
65,212 KB
testcase_25 AC 945 ms
65,244 KB
testcase_26 AC 936 ms
65,464 KB
testcase_27 AC 923 ms
65,148 KB
testcase_28 AC 952 ms
65,292 KB
testcase_29 AC 945 ms
63,576 KB
testcase_30 AC 938 ms
65,168 KB
testcase_31 AC 947 ms
65,360 KB
testcase_32 AC 973 ms
65,184 KB
testcase_33 AC 1,501 ms
82,764 KB
testcase_34 AC 1,512 ms
82,888 KB
testcase_35 AC 1,490 ms
82,972 KB
testcase_36 AC 1,486 ms
82,300 KB
testcase_37 AC 1,488 ms
82,536 KB
testcase_38 AC 1,502 ms
81,440 KB
testcase_39 AC 1,482 ms
82,748 KB
testcase_40 AC 1,514 ms
81,696 KB
testcase_41 AC 1,509 ms
81,896 KB
testcase_42 AC 1,498 ms
82,304 KB
testcase_43 AC 1,744 ms
85,264 KB
testcase_44 AC 1,741 ms
84,792 KB
testcase_45 AC 1,743 ms
85,060 KB
testcase_46 AC 1,750 ms
85,076 KB
testcase_47 AC 1,740 ms
84,772 KB
testcase_48 AC 1,740 ms
85,368 KB
testcase_49 AC 1,696 ms
85,172 KB
testcase_50 AC 1,721 ms
85,348 KB
testcase_51 AC 1,702 ms
85,512 KB
testcase_52 AC 1,689 ms
85,236 KB
testcase_53 AC 1,668 ms
85,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

public class No1705 {
	
	private static class KeyValue implements Comparable<KeyValue> {
		public Integer key;
		public Long value;
		KeyValue(int key, long value) {
			this.key = key;
			this.value = value;
		}
		public int compareTo(KeyValue kv) {
			int n = value.compareTo(kv.value);
			if (n == 0) {
				return key.compareTo(kv.key);
			} else {
				return n;
			}
		}
		public KeyValue max(KeyValue kv) {
			return this.compareTo(kv) >= 0 ? this : kv;
		}
	}
	
	private static class SegmentTree {
		private int n;
		private KeyValue[] dat;
		SegmentTree(int n) {
			this.n = 1;
			while (this.n < n) {
				this.n *= 2;
			}
			dat = new KeyValue[2*this.n-1];
			for (int i=0; i < this.n*2-1; i++) {
				dat[i] = new KeyValue(-1, -1L);
			}
		}
		public void update(int k, long a) {
			KeyValue kv = new KeyValue(k, a);
			k += n - 1;
			dat[k] = kv;
			while (k > 0) {
				k = (k - 1) / 2;
				dat[k] = dat[k * 2 + 1].max(dat[k * 2 + 2]);
			}
		}
		public int max() {
			return dat[0].key + 1;
		}
		public long dat(int i) {
			return dat[i + n - 1].value;
		}
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		int M = scan.nextInt();
		SegmentTree tree = new SegmentTree(M);
		for (int i=0; i < M; i++) {
			long a = scan.nextLong();
			tree.update(i, a);
		}
		int Q = scan.nextInt();
		for (int i=0; i < Q; i++) {
			int t = scan.nextInt();
			int x = scan.nextInt();
			long y = scan.nextLong();
			if (t == 1) {
				tree.update(x-1, tree.dat(x-1) + y);
			} else if (t == 2) {
				tree.update(x-1, tree.dat(x-1) - y);		
			} else {
				System.out.println(tree.max());
			}
		}
		scan.close();
	}

}
0