#pragma GCC optimize ("Ofast") #include using namespace std; void*wmem; char memarr[96000000]; template inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(char &c){ int i; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(unsigned x){ int s=0; char f[10]; while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(unsigned long long x){ int s=0; char f[21]; while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } while(s--){ my_putchar_unlocked(f[s]+'0'); } } int WRITER_DOUBLE_DIGIT = 15; inline int writerDigit_double(){ return WRITER_DOUBLE_DIGIT; } inline void writerDigit_double(int d){ WRITER_DOUBLE_DIGIT = d; } inline void wt_L(double x){ const int d = WRITER_DOUBLE_DIGIT; int k; int r; double v; if(x!=x || (x==x+1 && x==2*x)){ my_putchar_unlocked('E'); my_putchar_unlocked('r'); my_putchar_unlocked('r'); return; } if(x < 0){ my_putchar_unlocked('-'); x = -x; } x += 0.5 * pow(0.1, d); r = 0; v = 1; while(x >= 10*v){ v *= 10; r++; } while(r >= 0){ r--; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; v *= 0.1; my_putchar_unlocked(k + '0'); } if(d > 0){ my_putchar_unlocked('.'); v = 1; for(r=(0);r<(d);r++){ v *= 0.1; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; my_putchar_unlocked(k + '0'); } } } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } inline void wt_L(string &x){ int i=0; for(i=0;x[i]!='\0';i++){ my_putchar_unlocked(x[i]); } } template struct Arr1d{ int n; int mem; T*d; T& operator[](int a){ return d[a]; } void sort(){ reset(); std::sort(d, d+n); } int set_cumulative_sum; int cumulative_sum_mem; T*cumulative_sum; void setSum(void){ int i; set_cumulative_sum = 1; if(cumulative_sum_mem < n+1){ delete[] cumulative_sum; cumulative_sum = new T[n+1]; cumulative_sum_mem = n+1; } cumulative_sum[0] = 0; for(i=(0);i<(n);i++){ cumulative_sum[i+1] = cumulative_sum[i] + d[i]; } } T getSum(int i, int j){ if(set_cumulative_sum==0){ setSum(); } return cumulative_sum[j+1] - cumulative_sum[i]; } void reset(){ set_cumulative_sum = 0; } void constructor(){ n = mem = 0; d = NULL; set_cumulative_sum = 0; cumulative_sum_mem = 0; cumulative_sum = NULL; } void destructor(){ delete[] d; d = NULL; mem = n = 0; set_cumulative_sum = 0; cumulative_sum_mem = 0; delete[] cumulative_sum; cumulative_sum = NULL; } void constructor(int nn){ constructor(); malloc(nn); } void memory_expand(int nn){ if(mem < nn){ delete[] d; d = new T[nn]; mem = nn; } } void malloc(int nn){ reset(); memory_expand(nn); n = nn; } void setN(int nn){ reset(); memory_expand(nn); n = nn; } void set(vector &a){ int i; int nn = a.size(); setN(nn); for(i=(0);i<(nn);i++){ d[i] = a[i]; } } void set(int nn, T a[]){ int i; setN(nn); for(i=(0);i<(nn);i++){ d[i] = a[i]; } } void free(){ destructor(); } Arr1d(){ constructor(); } Arr1d(int nn){ constructor(nn); } ~Arr1d(){ destructor(); } } ; int N; int Q; int L; int R; int X; char S[100000]; Arr1d h[26]; int main(){ int KrdatlYV, i; wmem = memarr; rd(N); rd(Q); rd(S); for(i=(0);i<(N);i++){ S[i] -= 'a'; } for(i=(0);i<(26);i++){ h[i].setN(N); } for(i=(0);i<(26);i++){ int j; for(j=(0);j<(N);j++){ h[i][j] = 0; } } for(i=(0);i<(N);i++){ h[S[i]][i] = 1; } for(KrdatlYV=(0);KrdatlYV<(Q);KrdatlYV++){ rd(L);L += (-1); rd(R);R += (-1); rd(X);X += (-1); for(i=(0);i<(26);i++){ X -= h[i].getSum(L,R); if(X < 0){ wt_L((char)('a'+i)); wt_L('\n'); break; } } } return 0; } // cLay version 20210405-1 // --- original code --- // int N, Q, L, R, X; char S[1d5]; // Arr1d h[26]; // { // rd(N,Q,S); // rep(i,N) S[i] -= 'a'; // rep(i,26) h[i].setN(N); // rep(i,26) rep(j,N) h[i][j] = 0; // rep(i,N) h[S[i]][i] = 1; // rep(Q){ // rd(L--, R--, X--); // rep(i,26){ // X -= h[i].getSum(L,R); // if(X < 0) Wt((char)('a'+i)), break; // } // } // }