提交记录 20379
提交时间 |
评测时间 |
2023-10-13 21:21:28 |
2023-10-13 21:21:37 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+6;
using ull=unsigned long long;
char ch[N];
int n,rk[N],sa[N],ht[N];
ull hsh[N],pw[N],p=131;
bool cmp(int a,int b){
// if(ch[bl[be[a]]]==ch[bl[be[b]]]){
// int L=min(bl[be[a]]-a,bl[be[b]]-b);
// a+=L,b+=L;
// }
// while(a<n&&b<n&&ch[a]==ch[b])a++,b++;
// if(a>=n)return 1;
// if(b>=n)return 0;
// return ch[a]<ch[b];
int fl=0;
if(a>b)swap(a,b),fl=1;
int l=0,r=n-b-1,ans=-1;
while(r>=l){
int mid=(l+r)>>1;
if((hsh[a+mid]-hsh[a-1])*pw[b-a]==hsh[b+mid]-hsh[b-1])ans=mid,l=mid+1;
else r=mid-1;
}
// cerr<<a<<" "<<b<<" : "<<ans<<endl;
if(b+ans==n-1)return fl;
return fl^(ch[a+ans+1]<ch[b+ans+1]);
}
int main(){
cin>>ch;
n=strlen(ch);
pw[0]=1;
for(int i=1;i<n;i++)pw[i]=pw[i-1]*p;
for(int i=0;i<n;i++)hsh[i]=(ch[i]-28)*pw[i]+hsh[i-1];
for(int i=0;i<n;i++)sa[i]=i;
stable_sort(sa,sa+n,cmp);
for(int i=0;i<n;i++)rk[sa[i]]=i,printf("%d ",sa[i]);
puts("");
for(int i=0,k=0;i<n;i++){
if(rk[i]==0)continue;
k-=!!k;
while(ch[i+k]==ch[sa[rk[i]-1]+k])k++;
ht[rk[i]]=k;
}
for(int i=1;i<n;i++)printf("%d ",ht[i]);
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 41.19 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 39.63 us | 60 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #3 | 36.92 us | 60 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 42.83 us | 60 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 42.59 us | 60 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 42.41 us | 60 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 85.15 ms | 3 MB + 784 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 99.741 ms | 3 MB + 972 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 95.569 ms | 3 MB + 836 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 59.594 ms | 2 MB + 524 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 62.572 ms | 2 MB + 564 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 52.726 ms | 4 MB + 140 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 71.826 ms | 4 MB + 108 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #14 | 97.165 ms | 3 MB + 864 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #15 | 105.114 ms | 3 MB + 880 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #16 | 61.374 ms | 4 MB + 140 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #17 | 67.924 ms | 4 MB + 140 KB | Wrong Answer | Score: 0 | 显示更多 |
Subtask #1 Testcase #18 | 68.341 ms | 4 MB + 140 KB | Wrong Answer | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2025-09-13 09:17:05 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠