結果

問題 No.1471 Sort Queries
ユーザー miyo2580
提出日時 2024-02-05 19:36:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 197,568 KB
最終ジャッジ日時 2025-02-19 01:49:18
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:12: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   48 |       char ans;
      |            ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
using Graph = vector<vector<ll>>;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

// Mos algo
//vector<Q>はpush_backで
// D=sqrt(q)+1; W=n/D+1;
int D,W;
struct Q{
    int l,r,q;
    Q(int l,int r,int q):l(l),r(r),q(q){}
    bool operator<(const Q& a) const{
        if(r/W!=a.r/W)return r/W<a.r/W;
        return l<a.l;
    }
};

int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,q;
    cin>>n>>q;
    string s;cin>>s;
    Graph g(26,vec(n+1));
    rep(i,n){
      g[s[i]-'a'][i+1]=1;
    }
    rep(i,26){
      for(ll j=1;j<=n;j++){
        g[i][j]+=g[i][j-1];
      }
    }
    rep(qi,q){
      ll l,r,x;
      cin>>l>>r>>x;
      l--;
      char ans;
      rep(i,26){
        x-=g[i][r]-g[i][l];
        if(x<=0){
          ans='a'+i;
          break;
        }
      }
      cout<<ans<<'\n';
    }
    return 0;
}
0