結果

問題 No.1471 Sort Queries
ユーザー Mister
提出日時 2021-04-09 21:23:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 1,022 ms
コンパイル使用メモリ 79,652 KB
最終ジャッジ日時 2025-01-20 13:25:16
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>

using namespace std;
using lint = long long;

void solve() {
    int n, q;
    cin >> n >> q;

    vector<vector<int>> cnt(n + 1, vector(26, 0));
    for (int i = 1; i <= n; ++i) {
        cnt[i] = cnt[i - 1];

        char c;
        cin >> c;
        ++cnt[i][c - 'a'];
    }

    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;
        --l;

        for (int c = 0; c < 26; ++c) {
            auto pcnt = cnt[r][c] - cnt[l][c];
            if (x <= pcnt) {
                cout << char('a' + c) << "\n";
                break;
            }
            x -= pcnt;
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0