QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562538#6837. AC Automatoncyj888TL 1359ms12972kbC++111.2kb2024-09-13 18:21:082024-09-13 18:21:10

Judging History

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

  • [2024-09-13 18:21:10]
  • 评测
  • 测评结果:TL
  • 用时:1359ms
  • 内存:12972kb
  • [2024-09-13 18:21:08]
  • 提交

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], t[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] == '?') {
		if (dn[u] > up[u]) s[u] = 'A'; else s[u] = 'C';
		dfs (1);
	}
	for (int v : e[u]) work (v);
	return ;
}
int main () {
	n = read (), q = read (), cin >> t + 1; ott (i, 2, n) e[read ()].pb (i);
	ott (i, 1, n) s[i] = t[i]; dfs (1);
	work (1); while (q --) {
		int x = read (); char c = getchar ();
		t[x] = c; ott (i, 1, n) s[i] = t[i];
		dfs (1); res = 0, work (1);
		ott (i, 1, n) if (s[i] == 'C') res += up[i];
		printf ("%d\n", res);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12972kb

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: 1359ms
memory: 12044kb

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:


result: