QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#562862 | #6837. AC Automaton | cyj888 | TL | 6ms | 12548kb | C++11 | 1.0kb | 2024-09-13 21:46:25 | 2024-09-13 21:46:25 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define ott(i,l,r) for (int i = l; i <= r; i ++)
#define tto(i,l,r) for (int i = r; i >= l; i --)
using namespace std;
using ll = long long;
int read () {
int x = 0; bool f = 0; char c = getchar ();
while (!isdigit (c)) f |= (c == '-'), c = getchar ();
while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
if (f) x = -x; return x;
}
const int N = 3e5 + 110;
int n, q, res;
vector <int> e[N];
int up[N], dn[N];
char s[N];
void dfs (int u) {
dn[u] = 0;
for (int v : e[u]) {
up[v] = up[u] + (s[u] != 'C');
dfs (v);
dn[u] += dn[v] + (s[v] != 'A');
}
return ;
}
void work (int u) {
if (s[u] == 'A') res += dn[u];
else if (s[u] == '?') res += max (0, dn[u] - up[u]);
for (int v : e[u]) work (v);
return ;
}
int main () {
n = read (), q = read (), cin >> s + 1; ott (i, 2, n) e[read ()].pb (i);
dfs (1);
work (1); while (q --) {
int x = read (); char c = getchar ();
s[x] = c;
dfs (1); res = 0, work (1);
printf ("%d\n", res);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 11720kb
input:
5 3 AC??C 1 2 2 1 1 ? 4 A 2 ?
output:
4 3 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 6ms
memory: 12548kb
input:
1000 1000 AC?ACCCCC?CCA??CCCCC?A?AC?C??C?ACCCACC?C?CCC?CACACA???????C?????CC?C?AAAAACCA??AAAACACACA???AACAC?CCC?CAC?AAAACCAC???ACAA??A??A?CA?A?ACACACCAA?ACACA?AC??AC??ACAAACCC??CAA?A???CC?AA??AC???A?CCCC??CACCAACC?AA?C?AAACCCA?AAA??C?CC??CACCACAACCA?AACCC?A?CCC?CC???AA?CACCCAAC??CAA??C?AA??CA???CAAA...
output:
2344 2345 2342 2342 2768 2768 2772 2772 2772 2772 2772 2772 2772 2767 2767 2767 2767 2764 2766 2766 2769 2765 2761 2764 2767 2772 2772 2772 2772 2772 2772 2777 2777 2777 2777 2774 2771 2774 2782 2778 2778 2772 2768 2772 2772 2772 2772 2772 2774 2774 2778 2781 2781 2779 2782 2784 2787 2782 2786 2788 ...
result:
ok 1000 lines
Test #3:
score: -100
Time Limit Exceeded
input:
300000 300000 AAA?CA?AA?AC?A?CCA?AACCAAA???CA?ACCAACCCCAACAAA?CCAAAC?A?C??CC?C?C?CCCA?CAA?ACA??C?C?AC??CA??ACA?AA???CACAAA?CACCCCCCC?A?AAAAAC?AACCA????CCC?C?AAACCCAA?C???CCCC?AAACAAA???A?CAAC??A??A??CCCC??AA?C??ACA?AACAAA????CAA???AAAAACC?C?CCA?CCAA?AAC?CC?CA?A??CC??CCAC??C??????AAC?AA?AA?AAC?C??AAC...
output:
2111015347 2111015347 2111162713 2111181743 2111078215 2111023909 2111023909 2111023909 2111065325 2111065325 2111065325 2110974323 2110872149 2110872149 2110872149 2110974903 2110964225 2110854270 2110745666 2110745666 2110658649 2110658649 2110681731 2110681731 2110681731 2110725806 2110725806 211...