結果

問題 No.1471 Sort Queries
ユーザー matsuura yutomatsuura yuto
提出日時 2023-07-20 18:45:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,817 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 179,604 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 19:14:55
合計ジャッジ時間 3,546 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 11 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 8 ms
4,348 KB
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 7 ms
4,348 KB
testcase_22 AC 6 ms
4,348 KB
testcase_23 AC 14 ms
4,348 KB
testcase_24 AC 14 ms
4,348 KB
testcase_25 AC 20 ms
4,348 KB
testcase_26 AC 16 ms
4,348 KB
testcase_27 AC 16 ms
4,348 KB
testcase_28 AC 16 ms
4,348 KB
testcase_29 AC 15 ms
4,348 KB
testcase_30 AC 14 ms
4,348 KB
testcase_31 AC 21 ms
4,348 KB
testcase_32 AC 23 ms
4,348 KB
testcase_33 AC 25 ms
4,348 KB
testcase_34 AC 25 ms
4,348 KB
testcase_35 AC 26 ms
4,348 KB
testcase_36 AC 22 ms
4,348 KB
testcase_37 AC 22 ms
4,348 KB
testcase_38 AC 24 ms
4,348 KB
testcase_39 AC 24 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
struct Mo {
  int n;
  vector< pair< int, int > > lr;

  explicit Mo(int n) : n(n) {}

  void add(int l, int r) { /* [l, r) */
    lr.emplace_back(l, r);
  }

  template< typename AL, typename AR, typename EL, typename ER, typename O >
  void build(const AL &add_left, const AR &add_right, const EL &erase_left, const ER &erase_right, const O &out) {
    int q = (int) lr.size();
    int bs = n / min< int >(n, sqrt(q));
    vector< int > ord(q);
    iota(begin(ord), end(ord), 0);
    sort(begin(ord), end(ord), [&](int a, int b) {
      int ablock = lr[a].first / bs, bblock = lr[b].first / bs;
      if(ablock != bblock) return ablock < bblock;
      return (ablock & 1) ? lr[a].second > lr[b].second : lr[a].second < lr[b].second;
    });
    int l = 0, r = 0;
    for(auto idx : ord) {
      while(l > lr[idx].first) add_left(--l);
      while(r < lr[idx].second) add_right(r++);
      while(l < lr[idx].first) erase_left(l++);
      while(r > lr[idx].second) erase_right(--r);
      out(idx);
    }
  }

  template< typename A, typename E, typename O >
  void build(const A &add, const E &erase, const O &out) {
    build(add, add, erase, erase, out);
  }
};
int main(){
  int N,Q; cin>>N>>Q;
  string S; cin>>S;
  Mo mo(N);
  int X[Q];
  for(int i=0;i<Q;i++){
    int l,r; cin>>l>>r;
    mo.add(l-1,r);
    cin>>X[i];
  }
  vector<int> cnt(26,0);
  vector<char> ans(Q);
  auto add = [&](int i) {
    cnt[S[i]-'a']++;
  };
  auto erase = [&](int i) {
    cnt[S[i]-'a']--;
  };
  auto out = [&](int q) {
    int sum=0;
    for(int i=0;i<26;i++){
      sum+=cnt[i];
      if(sum>=X[q]){
        ans[q]='a'+i;
        break;
      }
    }
  };
  mo.build(add, erase, out);
  for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
}
0