結果
問題 |
No.1705 Mode of long array
|
ユーザー |
![]() |
提出日時 | 2021-11-29 17:47:32 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 956 ms / 3,000 ms |
コード長 | 2,681 bytes |
コンパイル時間 | 5,464 ms |
コンパイル使用メモリ | 78,252 KB |
実行使用メモリ | 60,432 KB |
最終ジャッジ日時 | 2024-07-02 13:01:28 |
合計ジャッジ時間 | 34,210 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); int m = sc.nextInt(); Numbers[] numbers = new Numbers[m + 1]; TreeSet<Numbers> set = new TreeSet<>(); for (int i = 1; i <= m; i++) { numbers[i] = new Numbers(i, sc.nextLong()); set.add(numbers[i]); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int type = sc.nextInt(); int x = sc.nextInt(); long y = sc.nextLong(); if (type == 1) { set.remove(numbers[x]); numbers[x].add(y); set.add(numbers[x]); } else if (type == 2) { set.remove(numbers[x]); numbers[x].add(-y); set.add(numbers[x]); } else { sb.append(set.last()).append("\n"); } } System.out.print(sb); } static class Numbers implements Comparable<Numbers> { int num; long value; public Numbers(int num, long value) { this.num = num; this.value = value; } public int hashCode() { return num; } public boolean equals(Object o) { Numbers x = (Numbers)o; return x.num == num; } public int compareTo(Numbers another) { if (value == another.value) { return num - another.num; } else if (value < another.value) { return -1; } else { return 1; } } public String toString() { return String.valueOf(num); } public void add(long x) { value += x; } } } 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 double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }