結果
| 問題 |
No.1705 Mode of long array
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-30 13:10:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,772 ms / 3,000 ms |
| コード長 | 1,755 bytes |
| コンパイル時間 | 3,350 ms |
| コンパイル使用メモリ | 78,784 KB |
| 実行使用メモリ | 77,400 KB |
| 最終ジャッジ日時 | 2024-07-03 07:29:07 |
| 合計ジャッジ時間 | 66,102 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
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();
}
}