結果

問題 No.1471 Sort Queries
ユーザー tentententen
提出日時 2022-08-05 09:14:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,709 bytes
コンパイル時間 3,195 ms
コンパイル使用メモリ 74,800 KB
実行使用メモリ 61,560 KB
最終ジャッジ日時 2023-10-13 07:36:25
合計ジャッジ時間 10,174 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,308 KB
testcase_01 AC 43 ms
49,392 KB
testcase_02 AC 42 ms
49,320 KB
testcase_03 AC 44 ms
49,632 KB
testcase_04 AC 44 ms
49,408 KB
testcase_05 AC 44 ms
49,316 KB
testcase_06 AC 43 ms
49,564 KB
testcase_07 AC 43 ms
49,464 KB
testcase_08 AC 44 ms
49,372 KB
testcase_09 AC 44 ms
49,340 KB
testcase_10 AC 44 ms
49,472 KB
testcase_11 AC 45 ms
49,460 KB
testcase_12 AC 44 ms
49,624 KB
testcase_13 AC 111 ms
52,428 KB
testcase_14 AC 111 ms
52,348 KB
testcase_15 AC 124 ms
52,624 KB
testcase_16 AC 113 ms
51,960 KB
testcase_17 AC 106 ms
52,432 KB
testcase_18 AC 77 ms
51,576 KB
testcase_19 AC 113 ms
52,480 KB
testcase_20 AC 126 ms
53,792 KB
testcase_21 AC 111 ms
52,368 KB
testcase_22 AC 106 ms
52,384 KB
testcase_23 AC 137 ms
59,012 KB
testcase_24 AC 135 ms
59,116 KB
testcase_25 AC 145 ms
57,532 KB
testcase_26 AC 143 ms
59,232 KB
testcase_27 AC 138 ms
58,468 KB
testcase_28 AC 143 ms
58,992 KB
testcase_29 AC 139 ms
59,300 KB
testcase_30 AC 139 ms
58,984 KB
testcase_31 AC 138 ms
55,428 KB
testcase_32 AC 139 ms
55,452 KB
testcase_33 AC 158 ms
60,104 KB
testcase_34 AC 158 ms
59,248 KB
testcase_35 AC 188 ms
61,560 KB
testcase_36 AC 154 ms
59,496 KB
testcase_37 AC 154 ms
59,220 KB
testcase_38 AC 136 ms
54,928 KB
testcase_39 AC 153 ms
60,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] values = sc.next().toCharArray();
        int[][] sums = new int[n + 1][26];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 26; j++) {
                sums[i][j] = sums[i - 1][j];
            }
            sums[i][values[i - 1] - 'a']++;
        }
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int left = sc.nextInt() - 1;
            int right = sc.nextInt();
            int x = sc.nextInt();
            int count = 0;
            for (int i = 0; i < 26; i++) {
                count += sums[right][i] - sums[left][i];
                if (count >= x) {
                    sb.append((char)(i + 'a')).append("\n");
                    break;
                }
            }
        }
        System.out.print(sb);
    }
}

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 {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0