結果

問題 No.1471 Sort Queries
ユーザー tentententen
提出日時 2023-04-17 14:40:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 2,402 bytes
コンパイル時間 2,802 ms
コンパイル使用メモリ 89,064 KB
実行使用メモリ 50,512 KB
最終ジャッジ日時 2024-04-20 19:24:24
合計ジャッジ時間 8,952 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
37,076 KB
testcase_01 AC 47 ms
37,300 KB
testcase_02 AC 47 ms
37,476 KB
testcase_03 AC 51 ms
37,000 KB
testcase_04 AC 51 ms
37,128 KB
testcase_05 AC 47 ms
37,572 KB
testcase_06 AC 50 ms
37,360 KB
testcase_07 AC 48 ms
37,424 KB
testcase_08 AC 50 ms
37,572 KB
testcase_09 AC 50 ms
37,516 KB
testcase_10 AC 48 ms
37,076 KB
testcase_11 AC 50 ms
37,340 KB
testcase_12 AC 50 ms
36,980 KB
testcase_13 AC 123 ms
41,316 KB
testcase_14 AC 123 ms
44,152 KB
testcase_15 AC 129 ms
45,324 KB
testcase_16 AC 121 ms
40,528 KB
testcase_17 AC 111 ms
43,008 KB
testcase_18 AC 88 ms
39,220 KB
testcase_19 AC 120 ms
40,468 KB
testcase_20 AC 137 ms
45,860 KB
testcase_21 AC 120 ms
43,776 KB
testcase_22 AC 112 ms
41,228 KB
testcase_23 AC 147 ms
46,988 KB
testcase_24 AC 140 ms
46,200 KB
testcase_25 AC 157 ms
50,512 KB
testcase_26 AC 145 ms
47,256 KB
testcase_27 AC 141 ms
48,000 KB
testcase_28 AC 132 ms
43,072 KB
testcase_29 AC 152 ms
46,400 KB
testcase_30 AC 143 ms
46,008 KB
testcase_31 AC 158 ms
48,448 KB
testcase_32 AC 161 ms
50,056 KB
testcase_33 AC 155 ms
49,868 KB
testcase_34 AC 159 ms
49,932 KB
testcase_35 AC 156 ms
49,840 KB
testcase_36 AC 165 ms
47,804 KB
testcase_37 AC 153 ms
47,512 KB
testcase_38 AC 157 ms
45,156 KB
testcase_39 AC 163 ms
49,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
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();
        char[] inputs = sc.next().toCharArray();
        int[][] counts = new int[n + 1][26];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 26; j++) {
                counts[i][j] = counts[i - 1][j];
            }
            counts[i][inputs[i - 1] - 'a']++;
        }
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int left = sc.nextInt();
            int right = sc.nextInt();
            int idx = sc.nextInt();
            int[] current = new int[26];
            for (int i = 0; i < 26; i++) {
                current[i] = counts[right][i] - counts[left - 1][i];
            }
            int ans = 0;
            int value = 0;
            for (int i = 0; i < 26 && value < idx; i++) {
                value += current[i];
                ans = i;
            }
            sb.append((char)(ans + 'a')).append("\n");
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0