QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563375#6837. AC Automatoncyj888WA 0ms14164kbC++111.7kb2024-09-14 10:39:332024-09-14 10:39:34

Judging History

你现在查看的是最新测评结果

  • [2024-09-14 10:39:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14164kb
  • [2024-09-14 10:39:33]
  • 提交

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, acnt;
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], ++ acnt;
	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] == '?') 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 ;
}
void work (int u) {
	for (int v : e[u]) work (v);
	return ;
}

int main () {
	n = read (), q = read (), cin >> s + 1; ott (i, 2, n) e[fa[i] = read ()].pb (i);
	dfs (1);
	work (1); while (q --) {
		int x = read (); char c = getchar ();
		if (s[x] != 'C') cup (x, -1); if (s[x] != 'A') cdn (fa[x], -1), res -= acnt;
		if (s[x] == 'A') -- acnt; s[x] = c;  if (s[x] == 'A') ++ acnt;
		if (s[x] != 'C') cup (x, 1); if (s[x] != 'A') cdn (fa[x], 1), res += acnt;
		printf ("%d\n", res);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 12924kb

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

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:

2673
3000
2672
2998
2633
2633
2959
2959
2959
2959
2959
2959
2959
2630
2630
2630
2630
2303
2633
2633
2960
2632
2304
2634
2962
2962
2962
2634
2634
2634
2634
2961
2961
2961
2961
2634
2305
2633
2962
2635
2963
2636
2309
2638
2966
2966
2966
3293
3618
3618
3942
4266
4266
3943
4267
4590
4910
4589
4910
5230
...

result:

wrong answer 1st lines differ - expected: '2344', found: '2673'