結果
問題 | No.2710 How many more? |
ユーザー |
![]() |
提出日時 | 2024-04-01 17:27:27 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 |
ソースコード
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(); } } }