結果

問題 No.1471 Sort Queries
コンテスト
ユーザー 👑 terry_u16
提出日時 2021-04-09 22:11:07
言語 C++17(clang)
(clang++ 21.1.8 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 828 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 519 ms
コンパイル使用メモリ 135,680 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-11 11:13:01
合計ジャッジ時間 1,661 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <string>

int main()
{
    int n, queries;
    std::string s;

    std::cin >> n >> queries >> s;

    std::vector<std::vector<int>> counts(n + 1, std::vector<int>(26));

    for (size_t i = 0; i < s.length(); i++)
    {
        auto c = s[i] - 'a';
        counts[i + 1][c]++;

        for (size_t j = 0; j < 26; j++)
        {
            counts[i + 1][j] += counts[i][j];
        }
    }

    for (size_t q = 0; q < queries; q++)
    {
        int l, r, k;
        std::cin >> l >> r >> k;
        l--;

        int sum = 0;

        for (size_t i = 0; i < 26; i++)
        {
            sum += counts[r][i] - counts[l][i];

            if (sum >= k)
            {
                std::cout << (char)(i + 'a') << std::endl;
                break;
            }
        }
    }
}
0