QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116318#6624. String ProblemSoyTonyWA 4ms20132kbC++142.2kb2023-06-28 15:07:532023-06-28 15:07:54

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 15:07:54]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:20132kb
  • [2023-06-28 15:07:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int maxn=1e6+10;

inline int read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}

int n;
char s[maxn];
int sa[maxn],rk[maxn<<1],cnt[maxn],oldsa[maxn],oldrk[maxn<<1];
int height[maxn];
bool cmp(int x,int y,int l){
    return oldrk[x]==oldrk[y]&&oldrk[x+l]==oldrk[y+l];
}
inline void get_sa(){
    int m=max(n,127);
    for(int i=1;i<=n;++i) ++cnt[rk[i]=s[i]];
    for(int i=1;i<=m;++i) cnt[i]+=cnt[i-1];
    for(int i=n;i>=1;--i) sa[cnt[rk[i]]--]=i;
    for(int l=1;;l<<=1){
        int k=0;
        for(int i=n;i+l>n;--i) oldsa[++k]=i;
        for(int i=1;i<=n;++i) if(sa[i]>l) oldsa[++k]=sa[i]-l;
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;++i) ++cnt[rk[oldsa[i]]];
        for(int i=1;i<=m;++i) cnt[i]+=cnt[i-1];
        for(int i=n;i>=1;--i) sa[cnt[rk[oldsa[i]]]--]=oldsa[i];
        for(int i=1;i<=n;++i) oldrk[i]=rk[i];
        k=0;
        for(int i=1;i<=n;++i) rk[sa[i]]=cmp(sa[i],sa[i-1],l)?k:++k;
        m=k;
        if(k==n) break;
    }
    for(int i=1,k=0;i<=n;++i){
        if(k) --k;
        while(s[i+k]==s[sa[rk[i]-1]+k]) ++k;
        height[rk[i]]=k;
    }
}

int stmn[maxn][20];
inline void build(){
    for(int i=1;i<=n;++i) stmn[i][0]=height[i];
    for(int k=1;k<=19;++k){
        for(int i=1;i+(1<<k)-1<=n;++i){
            stmn[i][k]=min(stmn[i][k-1],stmn[i+(1<<k-1)][k-1]);
        }
    }
}
inline int query(int l,int r){
    l=rk[l],r=rk[r];
    if(l>r) swap(l,r);
    ++l;
    int k=__lg(r-l+1);
    return min(stmn[l][k],stmn[r-(1<<k)+1][k]);
}
int now,nxt;
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    get_sa();
    // for(int i=1;i<=n;++i) cerr<<rk[i]<<" ";
    // cerr<<endl;
    build();
    now=1,nxt=0;
    for(int i=1;i<=n;++i){
        if(rk[i]>rk[now]){
            // cerr<<i+query(now,i)<<endl;
            if(!nxt||i+query(now,i)<=nxt+query(now,nxt)) nxt=i;
        }
        if(nxt&&nxt+query(now,nxt)==i){
            now=nxt,nxt=0;
        }
        // cerr<<"i:"<<i<<" now:"<<now<<" nxt:"<<nxt<<endl;
        printf("%d %d\n",now,i);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 17972kb

input:

potato

output:

1 1
1 2
3 3
3 4
3 5
5 6

result:

ok 12 tokens

Test #2:

score: 0
Accepted
time: 4ms
memory: 17912kb

input:

pbpbppb

output:

1 1
1 2
1 3
1 4
1 5
5 6
5 7

result:

ok 14 tokens

Test #3:

score: 0
Accepted
time: 2ms
memory: 18012kb

input:

dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61
1 62...

result:

ok 1990 tokens

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 20132kb

input:

gtgggtgttgggggtgtgggtgttggtttggggtggtgtgggttggtggggtgggttgttggttgggtttggggtgttgggggtgggttttggttgttggtggggttgttggtggtggggtgggttttgggttggtgggtgggtggttgtgttggttttttttgttgggtttgggtgttgttgtggtgggttttggttggggtgttggttggtgtggtgtgggttttggttttttgtttgtggtggtgttttgtttttggtggggtgtttgttgttttggggttggggtgggggttgtgg...

output:

1 1
2 2
2 3
2 4
2 5
2 6
2 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
6 19
6 20
6 21
6 22
6 23
23 24
23 25
23 26
23 27
23 28
27 29
27 30
27 31
27 32
27 33
27 34
27 35
27 36
27 37
27 38
27 39
27 40
27 41
27 42
27 43
27 44
27 45
27 46
27 47
27 48
27 49
27 50
27 51
27 52
27 53
27 54
27 55
27...

result:

wrong answer 17th words differ - expected: '8', found: '6'