結果

問題 No.1018 suffixsuffixsuffix
ユーザー chocoruskchocorusk
提出日時 2020-04-04 17:46:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,804 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 119,652 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2023-09-16 06:00:32
合計ジャッジ時間 12,011 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 213 ms
4,380 KB
testcase_10 AC 216 ms
4,376 KB
testcase_11 AC 224 ms
4,856 KB
testcase_12 AC 206 ms
4,456 KB
testcase_13 AC 210 ms
4,412 KB
testcase_14 AC 323 ms
7,016 KB
testcase_15 AC 316 ms
7,168 KB
testcase_16 AC 330 ms
7,424 KB
testcase_17 AC 309 ms
7,140 KB
testcase_18 AC 305 ms
7,196 KB
testcase_19 AC 159 ms
4,376 KB
testcase_20 AC 160 ms
4,380 KB
testcase_21 AC 163 ms
4,376 KB
testcase_22 AC 160 ms
4,376 KB
testcase_23 AC 165 ms
4,376 KB
testcase_24 AC 327 ms
7,052 KB
testcase_25 AC 357 ms
7,312 KB
testcase_26 AC 321 ms
7,032 KB
testcase_27 AC 333 ms
7,088 KB
testcase_28 AC 322 ms
6,980 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 165 ms
4,380 KB
testcase_36 WA -
testcase_37 AC 348 ms
7,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct SuffixArray{
	int n, k;
	vector<int> rk, tmp, sa;
	string s;
	SuffixArray(string s):n(s.size()), s(s), rk(s.size()+1), tmp(s.size()+1), sa(s.size()+1){
		auto compare_sa=[&](int i, int j){
			if(rk[i]!=rk[j]) return rk[i]<rk[j];
			else{
				int ri, rj;
				if(i+k<=n) ri=rk[i+k];
				else ri=-1;
				if(j+k<=n) rj=rk[j+k];
				else rj=-1;
				return ri<rj;
			}
		};
		for(int i=0; i<=n; i++){
			sa[i]=i;
			if(i<n){
				rk[i]=s[i]-'A';
			}else{
				rk[i]=-1;
			}
		}
		for(k=1; k<=n; k<<=1){
			sort(sa.begin(), sa.end(), compare_sa);
			tmp[sa[0]]=0;
			for(int i=1; i<=n; i++){
				tmp[sa[i]]=tmp[sa[i-1]];
				if(compare_sa(sa[i-1], sa[i])) tmp[sa[i]]++;
			}
			rk=tmp;
		}
	}
	int operator[](const int &k) const{
		return sa[k];
	}
};
int main()
{
	int n, q;
	ll m;
	cin>>n>>m>>q;
	string s;
	cin>>s;
	if(m==1){
		SuffixArray sa(s);
		while(q--){
			ll k; cin>>k;
			cout<<sa[k]+1<<" ";
		}
		cout<<endl;
		return 0;
	}
	ll c=0;
	SuffixArray sa(s+s);
	ll x[200020];
	x[0]=0;
	for(int i=1; i<=2*n; i++){
		x[i]=x[i-1]+((sa[i]<n)?(m-1):1);
	}
	while(q--){
		ll k; cin>>k;
		int j=lower_bound(x, x+2*n+1, k)-x;
		ll ans;
		if(sa[j]>=n){
			ans=sa[j]-n+n*(m-1)+1;
		}else{
			ans=n*(x[j]-k)+1+sa[j];
		}
		cout<<ans<<" ";
	}
	cout<<endl;
	return 0;
}
0