#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int op(int a,int b){ return min(a,b); } int e(){ return Inf32; } int X; bool f(int x){ return x>=X; } int main(){ int N,Q; cin>>N>>Q; string S; cin>>S; auto sa = suffix_array(S); auto la = lcp_array(S,sa); vector pos(N); rep(i,sa.size())pos[sa[i]] = i; vector sum(N); rep(i,sa.size()){ sum[i] = N - sa[i]; if(i!=0)sum[i] += sum[i-1]; } segtree seg(la); rep(_,Q){ int l,r; cin>>l>>r; l--; int p = pos[l]; X = r-l; int ll = seg.min_left(p); int rr = seg.max_right(ll); rr++; //cout<