結果

問題 No.1471 Sort Queries
ユーザー Mayimg
提出日時 2021-04-09 22:30:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 196,480 KB
最終ジャッジ日時 2025-01-20 14:47:52
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<vector<int>> cnt(n + 1, vector<int>(26));
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) cnt[i + 1][j] = cnt[i][j] + ((s[i] - 'a') == j);
  }
  while (q--) {
    int l, r, x;
    cin >> l >> r >> x;
    l--;
    int cur = 0;
    for (int j = 0; j < 26; j++) {
      int c = cnt[r][j] - cnt[l][j];
      cur += c;
      // cerr << c << " " << cur << " " << x << endl;
      if (cur >= x) {
        cout << (char) (j + 'a') << '\n';
        goto done;
      }
    }
    done:;
  }
  return 0;
}
0