結果

問題 No.1471 Sort Queries
ユーザー neko_the_shadowneko_the_shadow
提出日時 2021-04-14 11:04:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 5,063 bytes
コンパイル時間 2,980 ms
コンパイル使用メモリ 92,588 KB
実行使用メモリ 62,724 KB
最終ジャッジ日時 2023-09-13 01:00:43
合計ジャッジ時間 10,674 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
35,284 KB
testcase_01 AC 55 ms
35,152 KB
testcase_02 AC 54 ms
35,036 KB
testcase_03 AC 61 ms
35,436 KB
testcase_04 AC 64 ms
35,604 KB
testcase_05 AC 58 ms
35,224 KB
testcase_06 AC 54 ms
35,168 KB
testcase_07 AC 60 ms
35,380 KB
testcase_08 AC 65 ms
35,732 KB
testcase_09 AC 59 ms
35,432 KB
testcase_10 AC 56 ms
35,616 KB
testcase_11 AC 63 ms
35,848 KB
testcase_12 AC 66 ms
35,492 KB
testcase_13 AC 150 ms
40,080 KB
testcase_14 AC 141 ms
39,724 KB
testcase_15 AC 159 ms
41,592 KB
testcase_16 AC 147 ms
40,272 KB
testcase_17 AC 144 ms
39,456 KB
testcase_18 AC 124 ms
38,972 KB
testcase_19 AC 153 ms
41,444 KB
testcase_20 AC 162 ms
41,228 KB
testcase_21 AC 145 ms
39,696 KB
testcase_22 AC 137 ms
39,480 KB
testcase_23 AC 175 ms
42,412 KB
testcase_24 AC 175 ms
44,620 KB
testcase_25 AC 195 ms
44,220 KB
testcase_26 AC 173 ms
41,700 KB
testcase_27 AC 179 ms
44,140 KB
testcase_28 AC 184 ms
44,564 KB
testcase_29 AC 174 ms
44,804 KB
testcase_30 AC 170 ms
42,404 KB
testcase_31 AC 194 ms
44,340 KB
testcase_32 AC 195 ms
58,904 KB
testcase_33 AC 199 ms
58,392 KB
testcase_34 AC 191 ms
59,268 KB
testcase_35 AC 199 ms
56,932 KB
testcase_36 AC 197 ms
58,776 KB
testcase_37 AC 195 ms
59,240 KB
testcase_38 AC 249 ms
62,724 KB
testcase_39 AC 189 ms
56,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package _1471;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.function.Supplier;
import java.util.regex.Pattern;

public class Main {
    public void exec() {
        int n = stdin.nextInt();
        int q = stdin.nextInt();
        String s = stdin.nextString();
        
        int[][] a = new int[26][n+1];
        for (int ch = 'a'; ch <= 'z'; ch++) {
            for (int i = 0; i < n; i++) {
                 a[ch-'a'][i+1] += a[ch-'a'][i] + (s.charAt(i)==ch ? 1 : 0);
            }
        }
        
        for (int i = 0; i < q; i++) {
            int l = stdin.nextInt()-1;
            int r = stdin.nextInt()-1;
            int x = stdin.nextInt();
            for (char ch = 'a'; ch <= 'z'; ch++) {
                x -= a[ch-'a'][r+1] - a[ch-'a'][l];
                if (x <= 0) {
                    stdout.println(ch);
                    break;
                }
            }
        }
    }
    
    private static final Stdin stdin = new Stdin(System.in);
    private static final Stdout stdout = new Stdout(System.out);

    public static void main(String[] args) {
        try {
            new Main().exec();
        } finally {
            stdout.flush();
        }
    }

    public static class Stdin {
        private Deque<String> queue;
        private BufferedReader in;
        private Pattern space;

        public Stdin(InputStream in) {
            this.queue = new ArrayDeque<>();
            this.in = new BufferedReader(new InputStreamReader(in));
            this.space = Pattern.compile(" ");
        }

        public String nextString() {
            if (queue.isEmpty()) {
                try {
                    String line = in.readLine();
                    if (line == null) {
                        throw new EOFException();
                    }
                    space.splitAsStream(line).forEach(this.queue::addLast);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return queue.removeFirst();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public double nextDouble() {
            return Double.parseDouble(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }
        
        public BigInteger nextBigInteger() {
            return new BigInteger(nextString());
        }

        public String[] nextStringArray(int n) {
            String[] a = new String[n];
            for (int i = 0; i < n; i++) a[i] = nextString();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) a[i] = nextDouble();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
        
        public BigInteger[] nexBigIntegerArray(int n) {
            BigInteger[] a = new BigInteger[n];
            for (int i = 0; i < n; i++) a[i] = nextBigInteger();
            return a;
        }
        
        public List<Integer> nextIntegerList(int n) {
            return nextList(n, this::nextInt);
        }
        
        public List<Long> nextLongList(int n) {
            return nextList(n, this::nextLong);
        }
        
        public List<Double> nextDoubleList(int n) {
            return nextList(n, this::nextDouble);
        }
        
        public List<String> nextStringList(int n) {
            return nextList(n, this::nextString);
        }
        
        public List<BigInteger> nextBigIntegerList(int n) {
            return nextList(n, this::nextBigInteger);
        }
        
        private <T> List<T> nextList(int n, Supplier<T> supplier) {
            List<T> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(supplier.get());
            return a;
        }
    }

    public static class Stdout {
        private PrintWriter stdout;

        public Stdout(PrintStream stdout) {
            this.stdout =  new PrintWriter(stdout, false);
        }

        public void println(Object ... objs) {
            for (int i = 0, len = objs.length; i < len; i++) {
                stdout.print(objs[i]);
                if (i != len-1) stdout.print(' ');
            }
            stdout.println();
        }

        public void flush() {
            stdout.flush();
        }
    }
}
0