結果
問題 | No.1018 suffixsuffixsuffix |
ユーザー | HIR180 |
提出日時 | 2020-04-03 22:30:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,503 bytes |
コンパイル時間 | 3,015 ms |
コンパイル使用メモリ | 203,416 KB |
実行使用メモリ | 19,540 KB |
最終ジャッジ日時 | 2024-07-03 04:35:05 |
合計ジャッジ時間 | 12,983 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | WA | - |
testcase_37 | RE | - |
コンパイルメッセージ
main.cpp: In function 'std::string reduce(std::string)': main.cpp:141:1: warning: control reaches end of non-void function [-Wreturn-type] 141 | } | ^
ソースコード
//Let's join Kaede Takagaki Fan Club !! #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() template<class T> void dmp(T a){ rep(i,a.size()) cout << a[i] << " "; cout << endl; } template<class T> bool chmax(T&a, T b){ if(a < b){ a = b; return 1; } return 0; } template<class T> bool chmin(T&a, T b){ if(a > b){ a = b; return 1; } return 0; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } int NN,k; int ran[400005]; int tmp[400005]; int sa[400005]; bool compare_sa(int i,int j) { if(ran[i] != ran[j]) return ran[i] < ran[j]; else { int ri = i+k<=NN ? ran[i+k]: -1; int rj = j+k<=NN ? ran[j+k]: -1; return ri < rj; } } void construct_sa(string S) { NN = S.size(); for(int i=0;i<=NN;i++) { sa[i] = i; ran[i] = i<NN?S[i]:-1; } for(k=1;k<=NN;k*=2) { sort(sa,sa+NN+1,compare_sa); tmp[sa[0]] = 0; for(int i=1;i<=NN;i++) { tmp[sa[i]] = tmp[sa[i-1]] + compare_sa(sa[i-1],sa[i]); } for(int i=0;i<=NN;i++) { ran[i] = tmp[i]; } } } int lcp[400005]; void construct_lcp(string S) { int n = S.size(); for(int i=0;i<=n;i++) ran[sa[i]] = i; int h = 0; lcp[0] = 0; for(int i=0;i<n;i++) { int j = sa[ran[i]-1]; if(h) h--; for(;j+h<n && i+h<n;h++) { if(S[j+h] != S[i+h]) break; } lcp[ran[i]-1] = h; } } string s; ll n,m,q; ll ans[100005]; ll ans2[100005]; string reduce(string str){ int sz = str.size(); for(int i=1;i<=sz;i++){ if(sz%i != 0) continue; string ret = str.substr(i); for(int j=i;j<sz;j++){ if(str[j-i] != str[j]) goto fail; } return ret; fail:; } } int main(){ ios::sync_with_stdio(false); cin >> n >> m >> q; cin >> s; s = reduce(s); m *= n/s.size(); n = s.size(); //cout << n << " " << m << endl; nxt:; if(m > 4){ int n = s.size(); s = s+s+s+s; construct_sa(s); construct_lcp(s); ll cur = 0; rep(i,100005) ans2[i] = -1; map<ll,int>M; vector<pair<ll,int>>vec; for(int i=1;i<=4*n;i++){ //cout << sa[i]%n << " " << (sa[i] < 3*n?1:0) << endl; if(sa[i] >= 3*n){ M[++cur] = sa[i]%n; } else if(ans2[sa[i]%n] == -1){ //answer for n*(m-2)+sa[i]%n ans2[sa[i]%n] = 1; vec.pb(mp(++cur, sa[i]%n)); cur += (m-2); } } rep(i,q) { ll a; g(a); if(M.find(a) != M.end()){ o(1LL*(m-1)*n + M[a] + 1, (i==q-1?0:1)); } else{ int x = POSL(vec, mp(a, INF)); x--; assert(vec[x].fi <= a && a <= vec[x].fi+m-2); int id = vec[x].sc; o(1LL*(m-2)*n+id - 1LL*n*(a-vec[x].fi) + 1, (i==q-1?0:1)); } } } else{ string t = ""; rep(i,m) t += s; construct_sa(t); construct_lcp(t); rep(i,q) { int a; g(a); o(1+sa[a], (i==q-1?0:1)); } } }