#include #include using namespace atcoder; //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector; using mat = vector; ll N,M,H,W,Q,K,A,B; string S; using P = pair; using tp = tuple; const ll INF = (1LL<<61); template bool chmin(T &a, const T b){ if(a > b) {a = b; return true;} else return false; } template bool chmax(T &a, const T b){ if(a < b) {a = b; return true;} else return false; } template void my_printv(std::vector v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i class BIT { //T has operator "+=" and can be initialized with 0. int n, n_2k; vector bitree; public: //make [0, n) BIT BIT(int _n) : bitree(_n + 1, 0) { n = n_2k = _n; while(n_2k & (n_2k - 1)) n_2k &= n_2k - 1; } //BIT[id] += x void add(int id, T x) { ++id; while (id <= n) { bitree[id] += x; id += id & -id; } } //sum of BIT[0, id] T sum(int id) { ++id; T temp(0); while (id > 0) { temp += bitree[id]; id -= id & -id; } return temp; } //sum of BIT[l, r) T range_sum(int l, int r) { return sum(r-1) - sum(l-1); } //return i in [0, n] //i = argmin_{j} (BIT[0, j] >= x) //T should have bool operator '<' int lower_bound(T x){ int id = n_2k; T temp(0); for(int plus = id; plus; id |= (plus>>=1)){ if(id <= n && temp + bitree[id] < x) temp += bitree[id]; else id ^= plus; } return id; } }; struct query{ int id, l, r, x, lb, ub; query(int a, int b, int c, int d, int e, int f) : id(a), l(b), r(c), x(d), lb(e), ub(f){} int cen(){return (ub + lb) / 2;} }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N>>Q>>S; int _n = N; vector qs; rep(i, Q){ int l, r, x; cin>>l>>r>>x; --l; qs.emplace_back(i, l, r, x, -1, _n - 1); } vec ord(N); iota(ALL(ord), 0); sort(ALL(ord), [&](int x, int y){ return S[x] < S[y];}); while(_n){ auto q = qs.begin(); BIT bit(N); rep(i, N){ bit.add(ord[i], 1); while(q != qs.end() && q->cen() == i){ (bit.range_sum(q->l, q->r) < q->x ? q->lb : q->ub) = q->cen(); ++q; } } sort(ALL(qs), [](auto a, auto b){ return a.cen() < b.cen(); }); //for(auto e : qs) cout<>= 1; } sort(ALL(qs), [](auto a, auto b){ return a.id < b.id; }); for(auto q : qs) cout<