UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214001#2739. 阿空的核聚变a_sad_soul1002115ms118848kbC++11946b2024-11-14 22:08:512024-11-14 23:09:21

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN =5e5+10;
char s[MAXN];
int nxt[MAXN][30];
int p[MAXN][30];
int n;
void Init(){
    for(int i=1;i<=n+4;++i){
        for(int j=0;j<=20;++j)nxt[i][j]=n+3;
        for(int j=0;j<=26;++j)p[i][j]=n+3;
    }
    for(int i=n;i;--i){
        p[i][s[i]-'a']=i+1;
        for(int j=s[i]-'a'+1;j<=26;++j)p[i][j]=p[p[i][j-1]][j-1];
        nxt[i][0]=p[i][26];
        for(int j=1;j<=20;++j)nxt[i][j]=nxt[nxt[i][j-1]][j-1];
        for(int j=0;j<26;++j)if(p[i][j]==n+3)p[i][j]=p[nxt[i][0]][j];
    }
}
bool check(int l,int r){
    for(int i=20;~i;--i){
        if(nxt[l][i]<=r+1)l=nxt[l][i];
        if(l==r+1)return true;
    }
    return false;
}
int main(){
    scanf("%s",s+1);n=strlen(s+1);Init();
    int q;scanf("%d",&q);
    while(q--){
        int l,r;scanf("%d%d",&l,&r);
        if(check(l,r))puts("Yes");
        else puts("No");
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

wwwwyyyvttttutsrqquuusstttuvutrrsvvwxvvwvvvvwuuvwvvwwuuurrssswywvvwvurrstxwvvxxxxxxyzvvvssrrsttvuuwy...

output:

No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 3000 lines

Test #2:

score: 10
Accepted
time: 1ms
memory: 1204kb

input:

wvvvvwwttuvwwyyxxwvvwwzywvttuusstuuwyyywwxyywvuttuuuttwxwwyyyxxzzxxxwvuuyyyyzvvvvwvvvvwwwztssuuuwwwy...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Y...

result:

ok 3000 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

zywwxyyzyyvuttwvvwxutssvuuvyyzzyxxyxxzzyyxxyxxxxzyxxwuuvwwxwwyxxyvvttuvxyyyxxyyyyyxxyyxwwxxyyyvuuwww...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 3000 lines

Test #4:

score: 10
Accepted
time: 0ms
memory: 1888kb

input:

zzzyywwxyzxxyzyyzzyyyyzyyzyxxzzzzyyyyyxxyyzzyxxzzyyzzzyyzyyzzzzyyyyzzzxwwwwxzzzzyyzxxyyyzzyyyyyyzzzy...

output:

No
No
No
Yes
No
Yes
No
No
Yes
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
N...

result:

ok 3000 lines

Test #5:

score: 10
Accepted
time: 2ms
memory: 1884kb

input:

yxxyxxzzyyxxyyxxxxxxxwvuuxvvwyyxxxxyyyyxxwwxzyxxyxxyyyxwvuttywvvxxxywwxywwxxwuuuuzxxyxwwxvvwwuuvxyww...

output:

No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No...

result:

ok 3000 lines

Test #6:

score: 10
Accepted
time: 0ms
memory: 1888kb

input:

xxyywvvxyuuuuvvwwxxxttuvvvzvvwwwyyywwsstuuttvvwvttuwvurrrrsqqrxxvvttttvxuuvwvusstvvxwwyxxzzxwwxutsss...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
N...

result:

ok 3000 lines

Test #7:

score: 10
Accepted
time: 494ms
memory: 118848kb

input:

yyzzzyyzzzyyzzzzyzzyyzyyzzyzzyzzzzyyzyyzzyzyzyyzyzyzzzzzzyzzyzzzyyyzyyzzyyyzzyzyyzzzyyzyyzzzyzyzyzyy...

output:

No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No...

result:

ok 1000000 lines

Test #8:

score: 10
Accepted
time: 568ms
memory: 118848kb

input:

yzzzzyzzyyzyzzzyyyzyyzyzzzyzyzzzzzzzyyyzyyzyzzzzyzzyyyyyzyyzyzyyzzzyzzyzzyzzzzzyyzyyyyyzyyyzzyzyzzyy...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
Yes
No
No
N...

result:

ok 1000000 lines

Test #9:

score: 10
Accepted
time: 486ms
memory: 118844kb

input:

yyyyxxyzxxxxxxwvuuvvwzxxwwvuuvuuxutssvutssuttxxyxxxvvttuvxxywwxxwwyywwxyyywwxzyxwwxxywwwwyyyywwxyyvv...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
N...

result:

ok 1000000 lines

Test #10:

score: 10
Accepted
time: 564ms
memory: 118844kb

input:

ywwxyyxxyzzzyxxyyyyzzzzzzyyzzyxxzzyyyxxzzzywwxzzyyzwwxxwwyyzyyzzzyyzyyyxwwyxxyyzyyyxxyyzyxxyyzzywwxw...

output:

No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
No
No
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No...

result:

ok 1000000 lines