提交记录 21623
提交时间 |
评测时间 |
2024-04-16 21:02:52 |
2024-04-16 21:02:57 |
#include<iostream>
#include<string.h>
using namespace std;
const int N=100005;
int n,sa[N],rk[N],h[N];
char a[N];
namespace SA{
int cnt[N],la[N];
void getsa(){
memset(cnt,0,sizeof(cnt));
for(int i=1;i<=n;++i)rk[i]=a[i],++cnt[a[i]];
for(int i=1;i<128;++i)cnt[i]+=cnt[i-1];
for(int i=n;i;--i)sa[cnt[a[i]]--]=i;
for(int o=1,now,m=128;o<n;o<<=1){
memset(cnt,0,sizeof(cnt));
now=0;
for(int i=1;i<=n;++i)++cnt[rk[i]];
for(int i=n-o+1;i<=n;++i)la[++now]=i;
for(int i=1;i<=n;++i)
if(sa[i]>o)la[++now]=sa[i]-o;
for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
for(int i=n;i;--i)sa[cnt[rk[la[i]]]--]=la[i];
m=0;
swap(la,rk);
for(int i=1;i<=n;++i)
if(la[sa[i]]==la[sa[i-1]]&&la[sa[i]+o]==la[sa[i-1]+o])rk[sa[i]]=m;
else rk[sa[i]]=++m;
if(m==n)break;
}
}
void getht(){
for(int i=1,o=0,la;i<=n;++i){
o=max(0,o-1);
la=sa[rk[i]-1];
while(a[la+o]==a[i+o])++o;
h[rk[i]]=o;
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>(a+1);
n=strlen(a+1);
SA::getsa();
SA::getht();
for(int i=1;i<=n;++i)
cout<<sa[i]<<" ";
cout<<'\n';
for(int i=2;i<=n;++i)
cout<<h[i]<<" ";
cout<<'\n';
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 77.97 us | 472 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #2 | 233.57 us | 1 MB + 220 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #3 | 233.04 us | 1 MB + 220 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 376.64 us | 1 MB + 220 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 376.75 us | 1 MB + 220 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 377.07 us | 1 MB + 220 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 20.165 ms | 2 MB + 840 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 36.411 ms | 3 MB + 4 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 22.247 ms | 2 MB + 892 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 14.557 ms | 2 MB + 304 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 15.394 ms | 2 MB + 344 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 28.082 ms | 3 MB + 196 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 26.737 ms | 3 MB + 164 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #14 | 23.666 ms | 2 MB + 920 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #15 | 23.37 ms | 2 MB + 936 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #16 | 26.852 ms | 3 MB + 196 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #17 | 26.541 ms | 3 MB + 196 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #18 | 26.76 ms | 3 MB + 196 KB | Accepted | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 18:48:28 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠