結果

問題 No.2710 How many more?
ユーザー tentententen
提出日時 2024-04-01 17:27:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 839 ms / 2,000 ms
コード長 2,069 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 80,000 KB
実行使用メモリ 74,000 KB
最終ジャッジ日時 2024-04-01 17:27:42
合計ジャッジ時間 14,465 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,984 KB
testcase_01 AC 52 ms
53,988 KB
testcase_02 AC 624 ms
67,852 KB
testcase_03 AC 623 ms
68,740 KB
testcase_04 AC 650 ms
68,472 KB
testcase_05 AC 480 ms
65,024 KB
testcase_06 AC 703 ms
67,940 KB
testcase_07 AC 305 ms
59,780 KB
testcase_08 AC 383 ms
62,696 KB
testcase_09 AC 749 ms
69,412 KB
testcase_10 AC 485 ms
65,888 KB
testcase_11 AC 543 ms
65,168 KB
testcase_12 AC 784 ms
68,764 KB
testcase_13 AC 816 ms
73,020 KB
testcase_14 AC 839 ms
73,184 KB
testcase_15 AC 828 ms
73,044 KB
testcase_16 AC 825 ms
73,140 KB
testcase_17 AC 804 ms
74,000 KB
testcase_18 AC 53 ms
53,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        }
    }
    
}
0