結果

問題 No.2361 Many String Compare Queries
ユーザー 沙耶花沙耶花
提出日時 2023-06-23 22:55:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 942 bytes
コンパイル時間 4,330 ms
コンパイル使用メモリ 261,676 KB
実行使用メモリ 10,980 KB
最終ジャッジ日時 2023-09-13 18:02:45
合計ジャッジ時間 7,433 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 229 ms
10,164 KB
testcase_12 AC 249 ms
10,248 KB
testcase_13 AC 237 ms
10,240 KB
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
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<int> pos(N);
	rep(i,sa.size())pos[sa[i]] = i;
	vector<long long> sum(N);
	rep(i,sa.size()){
		sum[i] = N - sa[i];
		if(i!=0)sum[i] += sum[i-1];
	}
	segtree<int,op,e> seg(la);
	rep(_,Q){
		int l,r;
		cin>>l>>r;
		l--;
		
		int p = pos[l];
		
		X = r-l;
		
		int ll = seg.min_left<f>(p);
		int rr = seg.max_right<f>(ll);
		rr++;
		//cout<<ll<<','<<rr<<endl;
		long long ans = rr-ll;
		ans *= X-1;
		if(ll!=0)ans += sum[ll-1];
		cout<<ans<<endl;
	}
	
	return 0;
}
0