結果
| 問題 |
No.1705 Mode of long array
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-10-11 16:00:31 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 970 ms / 3,000 ms |
| コード長 | 2,384 bytes |
| コンパイル時間 | 2,501 ms |
| コンパイル使用メモリ | 78,876 KB |
| 実行使用メモリ | 60,572 KB |
| 最終ジャッジ日時 | 2024-09-15 16:37:06 |
| 合計ジャッジ時間 | 35,370 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static long[] counts;
static Num[] nums;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
long n = sc.nextLong();
int m = sc.nextInt();
TreeSet<Num> stock = new TreeSet<>();
counts = new long[m];
nums = new Num[m];
for (int i = 0; i < m; i++) {
nums[i] = new Num(i);
counts[i] = sc.nextLong();
stock.add(nums[i]);
}
int q = sc.nextInt();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < q; i++) {
int type = sc.nextInt();
int x = sc.nextInt() - 1;
long y = sc.nextLong();
if (type == 1) {
stock.remove(nums[x]);
counts[x] += y;
stock.add(nums[x]);
} else if (type == 2) {
stock.remove(nums[x]);
counts[x] -= y;
stock.add(nums[x]);
} else {
sb.append(stock.last()).append("\n");
}
}
System.out.print(sb);
}
static class Num implements Comparable<Num> {
int idx;
public Num(int idx) {
this.idx = idx;
}
public int compareTo(Num another) {
if (counts[idx] == counts[another.idx]) {
return idx - another.idx;
} else if (counts[idx] > counts[another.idx]) {
return 1;
} else {
return -1;
}
}
public int hashCode() {
return idx;
}
public String toString() {
return String.valueOf(idx + 1);
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten