QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#563380 | #6837. AC Automaton | cyj888 | WA | 0ms | 13828kb | C++11 | 1.5kb | 2024-09-14 10:42:41 | 2024-09-14 10:42:41 |
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 fa[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');
}
if (s[u] == 'A') res += dn[u];
if (s[u] == '?') res += max (0, dn[u] - up[u]);
return ;
}
void cup (int u, int val) {
for (int v : e[u]) {
if (s[v] == '?') res -= max (0, dn[v] - up[v]);
up[v] += val;
if (s[v] == '?') res += max (0, dn[v] - up[v]);
cup (v, val);
}
return ;
}
void cdn (int u, int val) {
if (!u) return ;
if (s[u] == 'A') res += val;
if (s[u] == '?') res -= max (0, dn[u] - up[u]);
dn[u] += val;
if (s[u] == '?') res += max (0, dn[u] - up[u]);
cdn (fa[u], val);
return ;
}
int main () {
n = read (), q = read (), cin >> s + 1; ott (i, 2, n) e[fa[i] = read ()].pb (i);
dfs (1); while (q --) {
int x = read (); char c = getchar ();
if (s[x] != 'C') cup (x, -1); if (s[x] != 'A') cdn (fa[x], -1);
s[x] = c;
if (s[x] != 'C') cup (x, 1); if (s[x] != 'A') cdn (fa[x], 1);
printf ("%d\n", res);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13676kb
input:
5 3 AC??C 1 2 2 1 1 ? 4 A 2 ?
output:
4 3 3
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 13828kb
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:
2348 2351 2348 2350 2310 2310 2315 2315 2315 2315 2315 2315 2315 2310 2310 2310 2310 2307 2314 2314 2317 2313 2309 2315 2318 2318 2318 2315 2315 2315 2315 2320 2320 2320 2320 2315 2312 2316 2324 2319 2322 2316 2312 2316 2319 2319 2319 2322 2326 2326 2330 2334 2334 2331 2334 2339 2343 2338 2342 2345 ...
result:
wrong answer 1st lines differ - expected: '2344', found: '2348'