QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405637#8630. 字符树strcmp#0 416ms16080kbC++141.6kb2024-05-06 11:26:312024-05-06 11:26:33

Judging History

This is the latest submission verdict.

  • [2024-05-06 11:26:33]
  • Judged
  • Verdict: 0
  • Time: 416ms
  • Memory: 16080kb
  • [2024-05-06 11:26:31]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 1e6 + 10;
int fa[maxn], dep[maxn], n, m, X; char a[maxn], b[maxn], c[maxn], d[maxn], f[maxn];
inline int lca(int x, int y) {
    if (dep[x] < dep[y]) swap(x, y);
    while (dep[x] != dep[y]) x = fa[x];
    while (x != y) x = fa[x], y = fa[y];
    return x;
}
int main() {
    scanf("%d%d%d", &n, &m, &X);
    for (int i = 2; i <= n; i++) scanf("%d", &fa[i]);
    scanf("%s", a + 2);
    for (int i = 1; i <= n; i++) dep[i] = dep[fa[i]] + 1;
    while (m--) {
        int o, x, y;
        scanf("%d%d%d%s", &o, &x, &y, b + 1);
        int l = lca(x, y), p = 0, q = 0;
        if (o == 1) {
            int pre = 1, nxt = X;
            while (x != l) a[x] = b[pre], x = fa[x], ++pre;
            while (y != l) a[y] = b[nxt], y = fa[y], --nxt;
        }
        else {
            while (x != l) c[++p] = a[x], x = fa[x];
            while (y != l) d[++q] = a[y], y = fa[y];
            for (int i = q; i >= 1; i--) c[++p] = d[i];
            for (int i = 1; i <= p; i++) f[i] = 0;
            for (int i = 2, j = 0; i <= p; i++) {
                while (j && c[i] != c[j + 1]) j = f[j];
                if (c[i] == c[j + 1]) ++j;
                f[i] = j;
            }
            int ans = 0;
            for (int i = 1, j = 0; i <= p; i++) {
                while (j && b[j + 1] != c[i]) j = f[j];
                if (b[j + 1] == c[i]) ++j;
                if (j == X) ++ans;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 10044kb

input:

250 250 62
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 30 67 68 8 70 16 72 3 74 75 32 77 75 31 80 81 65 83 30 19 49 4 1 89 57 91 92 43 94 95 96 85 51 32 100 8...

output:

1
1
1
1
1
1
1
1
0
0
1
1
0
0
0
1
1
1
1
1
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
2
3
0
0
0
4
4
0
0
0
0
0
2
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
1
0
0
10
0
0
0
0
0
0
2
0
0
0
0
0
0
0
1
0
2
0
1
0
0
7

result:

wrong answer 10th numbers differ - expected: '1', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 47ms
memory: 14084kb

input:

500000 650 769
1 2 3 4 5 6 7 8 9 10 11 12 7 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

1
1
1
1
1
1
0
0
1
1
1
0
1
0
1
0
1
0
0
1
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
0
0
0
0
1
0
0
0
1
0
0
1
0
0
0
1
1
1
1
0
1
0
0
1
0
0
1
1
1
0
1
1
0
1
1
0
0
1
1
1
1
0
0
0
0
0
1
0
0
1
1
0
0
1
0
0
0
1
0
1
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 12th numbers differ - expected: '1', found: '0'

Subtask #3:

score: 0
Time Limit Exceeded

Test #21:

score: 10
Accepted
time: 151ms
memory: 14100kb

input:

500000 499998 1
1 2 3 4 5 6 7 8 1 1 11 12 13 14 15 16 1 1 19 20 21 22 23 24 1 26 1 28 29 30 1 32 33 34 35 1 37 38 39 40 41 42 43 1 45 46 47 48 49 50 1 52 53 54 55 56 57 1 1 60 61 62 63 64 65 66 67 68 69 1 71 1 73 1 75 76 77 78 79 80 81 82 83 1 1 86 87 88 89 1 91 92 93 94 95 96 97 98 99 100 101 102 1...

output:

2
0
6
4
8
1
3
6
5
1
8
3
11
4
6
1
3
0
2
0
2
0
1
1
3
1
1
3
1
2
1
3
4
5
4
4
5
0
0
4
1
1
5
5
0
0
1
0
1
5
0
0
4
0
0
2
3
5
13
3
3
6
0
9
0
5
1
5
0
0
4
2
4
0
0
4
0
2
6
1
4
1
3
0
1
3
7
1
0
1
5
0
0
0
3
0
0
3
1
7
1
1
0
10
0
5
7
1
0
0
2
0
0
0
0
4
0
3
0
1
5
1
1
0
0
2
0
2
8
4
4
2
4
1
3
14
6
2
5
16
0
0
10
5
0
0
5
...

result:

ok 250246 numbers

Test #22:

score: 10
Accepted
time: 416ms
memory: 16080kb

input:

499995 499996 1
1 2 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 6 27 28 29 30 31 32 33 34 35 36 37 38 39 37 41 42 27 44 45 46 43 48 49 50 32 52 53 54 55 56 9 58 59 60 61 62 63 64 65 41 67 68 69 70 71 72 73 74 75 76 51 78 79 80 81 82 83 14 85 86 87 88 89 90 61 92 93 94 93 96 97 98 9...

output:

25
119
1
38
5
27
42
23
4
28
29
3
21
23
63
21
34
9
5
56
4
11
56
3
4
32
48
4
39
6
75
44
4
3
52
7
3
71
84
78
10
6
59
25
4
70
90
9
5
52
10
59
3
24
48
28
15
63
76
43
67
1
24
6
29
37
29
50
4
28
47
14
1
4
58
43
34
2
1
23
2
3
35
57
0
52
24
3
22
34
32
2
17
13
38
5
36
0
3
115
61
36
50
61
50
52
11
3
48
4
88
18...

result:

ok 249848 numbers

Test #23:

score: 10
Accepted
time: 220ms
memory: 14092kb

input:

500000 500000 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 1 61 62 63 1 1 66 67 68 69 70 71 72 73 74 75 76 1 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

9
8
11
36
5
1
6
18
25
1
7
20
23
6
2
10
1
4
1
6
3
5
1
2
21
1
2
17
1
0
27
3
36
3
6
8
3
5
3
1
10
21
26
19
0
7
5
14
37
18
31
27
18
18
3
0
1
30
0
36
9
3
5
1
0
12
2
1
0
53
1
7
0
9
7
11
0
18
34
1
18
22
19
7
1
4
8
1
4
4
3
8
1
6
0
0
16
15
12
6
10
4
16
0
10
4
0
17
2
0
37
3
12
2
6
43
3
17
32
5
5
6
19
0
5
3
4
2...

result:

ok 249445 numbers

Test #24:

score: 0
Time Limit Exceeded

input:

500000 500000 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...

output:

17672
25594
24568
36011
16778
68155
51386
2299
1
727
27893
112385
59514
9221
87735
5482
7401
5909
66693
15958
8958
8439
18126
16553
7925
22449
38
35874
4427
140733
9113
2
49766
31636
11655
58122
49282
14144
27748
3741
26121
38539
125007
30785
3224
12580
11780
80245
82717
21451
11646
14234
13585
1832...

result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #41:

score: 0
Wrong Answer
time: 29ms
memory: 14044kb

input:

499997 9 40060
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...

output:

1
1
0
0
0
0

result:

wrong answer 5th numbers differ - expected: '1', found: '0'

Subtask #6:

score: 0
Time Limit Exceeded

Test #51:

score: 0
Time Limit Exceeded

input:

500000 62500 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...

output:

4670
5062
1323
298
1392
780
361
8956
1941
34
1756
2684
14229
973
24275
163
107
2742
3870
9933
792
3486
1640
367
275
154
4114
671
692
173
4139
220
585
4550
1851
90
716
224
2594
18604
25
459
249
124
491
1455
6
113
527
15322
28
50
10713
0
3515
203
36561
29
28
217
130
2597
6560
148
283
1
2
1254
8146
0
0...

result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #61:

score: 0
Time Limit Exceeded

input:

500000 100000 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...

output:

4
17986
30064
174788
38161
211015
106448
91622
13037
95529
151167
65689
66396
156390
28230
176115
272339
89286
141946
222298
17188
18213
11792
181011
84012
52257
5989
7
124253
93612
38134
153437
28244
265895
49422
144945
116186
6479
39619
48047
258474
169068
66514
134304
108561
96952
184906
38445
12...

result:


Subtask #8:

score: 0
Wrong Answer

Test #71:

score: 0
Wrong Answer
time: 5ms
memory: 10040kb

input:

25000 2500 10
1 2 3 4 5 6 7 8 9 10 1 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

0
0
1
1
1
75
1
3
0
3
8
0
1
1
1
0
1
1
3
0
57
0
0
1
1
1
0
1
0
2
0
0
0
5
0
0
1
0
1
2
0
1
81
3
1
0
0
0
19
0
0
0
0
0
0
0
0
0
0
1
0
2
0
1
1
0
0
0
1
0
0
0
3
0
1
0
0
0
3
5
0
0
0
0
0
1
0
0
0
5
2
0
5
6
4
1
0
1
0
22
0
0
0
1
1
0
0
1
5
0
0
0
41
2
1
0
1
1
0
0
0
1
4
0
0
0
0
1
0
0
3
2
0
0
2
0
39
2
0
0
3
0
0
61
0
1
...

result:

wrong answer 1st numbers differ - expected: '1', found: '0'

Subtask #9:

score: 0
Skipped

Dependency #8:

0%

Subtask #10:

score: 0
Skipped

Dependency #1:

0%