UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213916#2739. 阿空的核聚变WZRYWZWY1001929ms99316kbC++111.5kb2024-11-14 18:46:542024-11-14 23:00:43

answer

#include <bits/stdc++.h> // https://atcoder.jp/contests/mujin-pc-2017/submissions/1131727

using namespace std;

const int N = 500010;
const int LOG = 21;
const int ALPHA = 28;

int pr[N][LOG];
int f[N][ALPHA];
int a[N];
char foo[N];

int main() {
  scanf("%s", foo);
  int len = strlen(foo);
  for (int i = 0; i < len; i++) {
    a[i] = foo[i] - 'a';
  }
  for (int c = 0; c <= 26; c++) {
    f[len][c] = -1;
  }
  for (int i = len - 1; i >= 0; i--) {
    for (int c = 0; c <= 26; c++) {
      f[i][c] = -1;
    }
    f[i][a[i]] = i + 1;
    bool err = false;
    for (int c = a[i] + 1; c <= 26; c++) {
      int at = f[f[i][c - 1]][c - 1];
      if (at == -1) {
        err = true;
        break;
      }
      f[i][c] = at;
    }
    if (!err) {
      for (int c = 0; c < a[i]; c++) {
        f[i][c] = f[f[i][26]][c];
      }
    }
  }
  for (int i = 0; i <= len; i++) {
    pr[i][0] = f[i][26];
  }
  for (int j = 1; j < LOG; j++) {
    for (int i = 0; i <= len; i++) {
      if (pr[i][j - 1] == -1) {
        pr[i][j] = -1;
      } else {
        pr[i][j] = pr[pr[i][j - 1]][j - 1];
      }
    }
  }
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    for (int j = LOG - 1; j >= 0; j--) {
      if (pr[x][j] == -1) {
        continue;
      }
      if (pr[x][j] <= y) {
        x = pr[x][j];
      }
    }
    puts((x == y) ? "Yes" : "No");
  }
  return 0;
}

详细

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

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: 1200kb

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: 1772kb

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: 0ms
memory: 1768kb

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: 1768kb

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: 479ms
memory: 99312kb

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: 478ms
memory: 99316kb

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: 472ms
memory: 99312kb

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: 499ms
memory: 99316kb

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