結果
問題 | No.2710 How many more? |
ユーザー | tenten |
提出日時 | 2024-04-01 17:27:27 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 763 ms / 2,000 ms |
コード長 | 2,069 bytes |
コンパイル時間 | 2,221 ms |
コンパイル使用メモリ | 79,600 KB |
実行使用メモリ | 59,792 KB |
最終ジャッジ日時 | 2024-09-30 21:54:47 |
合計ジャッジ時間 | 12,713 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
36,956 KB |
testcase_01 | AC | 51 ms
36,964 KB |
testcase_02 | AC | 559 ms
54,480 KB |
testcase_03 | AC | 528 ms
53,368 KB |
testcase_04 | AC | 581 ms
56,616 KB |
testcase_05 | AC | 402 ms
50,236 KB |
testcase_06 | AC | 549 ms
54,232 KB |
testcase_07 | AC | 260 ms
45,004 KB |
testcase_08 | AC | 336 ms
47,432 KB |
testcase_09 | AC | 562 ms
55,448 KB |
testcase_10 | AC | 478 ms
50,540 KB |
testcase_11 | AC | 508 ms
51,328 KB |
testcase_12 | AC | 763 ms
56,372 KB |
testcase_13 | AC | 725 ms
59,792 KB |
testcase_14 | AC | 685 ms
58,948 KB |
testcase_15 | AC | 710 ms
58,796 KB |
testcase_16 | AC | 723 ms
59,648 KB |
testcase_17 | AC | 664 ms
59,680 KB |
testcase_18 | AC | 52 ms
37,256 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int q = sc.nextInt(); int[] points = new int[n]; TreeMap<Integer, Integer> counts = new TreeMap<>(); for (int i = 0; i < n; i++) { points[i] = sc.nextInt(); counts.put(points[i], counts.getOrDefault(points[i], 0) + 1); } int current = 0; for (int x : counts.keySet()) { current += counts.get(x); counts.put(x, current); } counts.put(0, 0); int[] lefts = new int[n]; int[] rights = new int[n]; for (int i = 0; i < n; i++) { lefts[i] = counts.lowerEntry(points[i]).getValue(); rights[i] = counts.get(points[i]); } StringBuilder sb = new StringBuilder(); while (q-- > 0) { int base = sc.nextInt() - 1; int target = sc.nextInt() - 1; sb.append(Math.max(0, lefts[base] - rights[target])).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }