結果
| 問題 |
No.2361 Many String Compare Queries
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2023-06-23 22:55:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 942 bytes |
| コンパイル時間 | 4,255 ms |
| コンパイル使用メモリ | 252,488 KB |
| 最終ジャッジ日時 | 2025-02-15 01:26:22 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 WA * 7 |
ソースコード
#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;
}
沙耶花