QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578820#6837. AC Automatoncyj888Compile Error//C++113.1kb2024-09-20 21:36:152024-09-20 21:36:15

Judging History

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

  • [2024-09-20 21:36:15]
  • 评测
  • [2024-09-20 21:36:15]
  • 提交

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 = 1e6 + 110;
int n, q, idx, B;
vector <int> e[N];
int up[N], dn[N], ans[N];
int fa[N][22], dfn[N], dep[N];
char s[N];
void dfs0 (int u) {
	dfn[u] = ++ idx, dep[u] = dep[fa[u][0]] + 1;
	ott (j, 1, 20) fa[u][j] = fa[fa[u][j - 1]][j - 1];
	for (int v : e[u]) dfs0 (v);
	return ;
}
int lca (int x, int y) {
	if (dep[x] < dep[y]) swap (x, y);
	tto (i, 0, 20) if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
	if (x == y) return x;
	tto (i, 0, 20) if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[x][i];
	return fa[x][0];
}
struct OPT {
	int op, x, v;
} a[N];
int t[N], bl[N];//belong&below
bool cmp (int x, int y) {
	return dfn[x] < dfn[y];
}
void fuck (int u, int z) {
	bl[u] = z;
	for (int v : e[u]) fuck (v, z);
	return ;
}
void cpr (int u) {
	int oth = 0;
	for (int v : e[u]) {
		if (bl[v]) cpr (v);
		else {
			if (!oth) oth = v, t[++ t[0]] = v;
			fuck (v, oth);
		}
	}
	return ;
}
void red (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]) {
		int ts = res;
		if (s[v] == '?') res -= max (0, dn[v] - up[v]);
		up[v] += val;
		ts = res;
		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] == 'A') res += val;
	if (s[u] == '?') res += max (0, dn[u] - up[u]);
	cdn (fa[u], val);
	return ;
}

void sol () {
	ott (i, 1, n) bl[i] = 0, E[i].clear ();
    ott (i, 1, m) t[++ t[0]] = a[i].x;
    sort (t + 1, t + 1 + t[0], cmp);
    ott (i, 2, m) t[++ t[0]] = lca (t[i - 1], t[i]); t[++ t[0]] = 1;
    sort (t + 1, t + 1 + t[0]), t[0] = unique (t + 1, t + 1 + t[0]) - t - 1;
    
    ott (i, 1, t[0]) bl[t[i]] = t[i];
    ott (i, 1, t[0]) {
    	int z = fa[t[i]][0], now = z;
    	while (!bl[now]) {
    		bl[now] = z;
    		now = fa[now][0];
		}
	}
	cpr (1), sort (t + 1, t + 1 + t[0], cmp);
	ott (i, 1, n) {
		
		//bl[i]<-i
	}
	ott (i, 2, t[0]) E[lca (t[i - 1], t[i])].pb (t[i]);
	
	ott (i, 1, m) {
		if (a[i].op < 0)
	}
	
}
int main () {
	n = read (), q = read (), cin >> s + 1; ott (i, 2, n) e[fa[i][0] = read ()].pb (i);
	B = (int)sqrt (q);
	dfs0 (1), red (1); ott (i, 1, q) {
		int x = read (); char c = getchar ();
		if (s[x] != 'C') a[++ m] = {-i, x, -1}; if (s[x] != 'A') a[++ m] = {i, fa[x], -1};
		s[x] = c;
		if (s[x] != 'C') a[++ m] = {-i, x, 1}; if (s[x] != 'A') a[++ m] = {i, fa[x], 1};
		if (i % B == 0 || i == q) {
			sol ();
			m = 0, res = 0, red (1);
		}
	}
	return 0;
}

Details

answer.code: In function ‘void red(int)’:
answer.code:59:17: error: ‘dfs’ was not declared in this scope; did you mean ‘ffs’?
   59 |                 dfs (v);
      |                 ^~~
      |                 ffs
answer.code:62:26: error: ‘res’ was not declared in this scope; did you mean ‘red’?
   62 |         if (s[u] == 'A') res += dn[u];
      |                          ^~~
      |                          red
answer.code:63:26: error: ‘res’ was not declared in this scope; did you mean ‘red’?
   63 |         if (s[u] == '?') res += max (0, dn[u] - up[u]);
      |                          ^~~
      |                          red
answer.code: In function ‘void cup(int, int)’:
answer.code:68:26: error: ‘res’ was not declared in this scope; did you mean ‘red’?
   68 |                 int ts = res;
      |                          ^~~
      |                          red
answer.code: In function ‘void cdn(int, int)’:
answer.code:79:26: error: ‘res’ was not declared in this scope; did you mean ‘red’?
   79 |         if (s[u] == '?') res -= max (0, dn[u] - up[u]);
      |                          ^~~
      |                          red
answer.code:80:40: error: ‘res’ was not declared in this scope; did you mean ‘red’?
   80 |         dn[u] += val; if (s[u] == 'A') res += val;
      |                                        ^~~
      |                                        red
answer.code:81:26: error: ‘res’ was not declared in this scope; did you mean ‘red’?
   81 |         if (s[u] == '?') res += max (0, dn[u] - up[u]);
      |                          ^~~
      |                          red
answer.code:82:18: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
   82 |         cdn (fa[u], val);
      |              ~~~~^
      |                  |
      |                  int*
answer.code:77:15: note:   initializing argument 1 of ‘void cdn(int, int)’
   77 | void cdn (int u, int val) {
      |           ~~~~^
answer.code: In function ‘void sol()’:
answer.code:87:34: error: ‘E’ was not declared in this scope
   87 |         ott (i, 1, n) bl[i] = 0, E[i].clear ();
      |                                  ^
answer.code:88:16: error: ‘m’ was not declared in this scope
   88 |     ott (i, 1, m) t[++ t[0]] = a[i].x;
      |                ^
answer.code:3:41: note: in definition of macro ‘ott’
    3 | #define ott(i,l,r) for (int i = l; i <= r; i ++)
      |                                         ^
answer.code:90:16: error: ‘m’ was not declared in this scope
   90 |     ott (i, 2, m) t[++ t[0]] = lca (t[i - 1], t[i]); t[++ t[0]] = 1;
      |                ^
answer.code:3:41: note: in definition of macro ‘ott’
    3 | #define ott(i,l,r) for (int i = l; i <= r; i ++)
      |                                         ^
answer.code:106:26: error: ‘E’ was not declared in this scope
  106 |         ott (i, 2, t[0]) E[lca (t[i - 1], t[i])].pb (t[i]);
      |                          ^
answer.code:108:20: error: ‘m’ was not declared in this scope
  108 |         ott (i, 1, m) {
      |                    ^
answer.code:3:41: note: in definition of macro ‘ott’
    3 | #define ott(i,l,r) for (int i = l; i <= r; i ++)
      |                                         ^
answer.code:110:9: error: expected primary-expression before ‘}’ token
  110 |         }
      |         ^
answer.code: In function ‘int main()’:
answer.code:118:39: error: ‘m’ was not declared in this scope
  118 |                 if (s[x] != 'C') a[++ m] = {-i, x, -1}; if (s[x] != 'A') a[++ m] = {i, fa[x], -1};
      |                                       ^
answer.code:118:79: error: ‘m’ was not declared in this scope
  118 |                 if (s[x] != 'C') a[++ m] = {-i, x, -1}; if (s[x] != 'A') a[++ m] = {i, fa[x], -1};
      |                                                                               ^
answer.code:120:39: error: ‘m’ was not declared in this scope
  120 |                 if (s[x] != 'C') a[++ m] = {-i, x, 1}; if (s[x] != 'A') a[++ m] = {i, fa[x], 1};
      |                                       ^
answer.code:120:78: error: ‘m’ was not declared in this scope
  120 |                 if (s[x] != 'C') a[++ m] = {-i, x, 1}; if (s[x] != 'A') a[++ m] = {i, fa[x], 1};
      |                                                                              ^
answer.code:123:25: error: ‘m’ was not declared in this scope
  123 |                         m = 0, res = 0, red (1);
      |                         ^
answer.code:123:32: error: ‘res’ was not declared in this scope; did you mean ‘red’?
  123 |                         m = 0, res = 0, red (1);
      |                                ^~~
      |                                red