Language: C++


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

pair<int, int>operator+(const pair<int, int>&p1, const pair<int, int>&p2) {
	return make_pair(p1.first + p2.first, p1.second + p2.second);
}

struct LazySeg {
	vector<pair<int, int>>seg; vector<int> laz;
	int width;
	LazySeg(int n, vector<pair<int, int>>&vec) :width(1) {
		while (width < n)width *= 2;
		seg.resize(width * 2 - 1);
		laz.resize(width * 2 - 1);
		for (int i = 0; i < vec.size(); ++i) {
			seg[i + width - 1] = vec[i];
		}
		for (int i = width - 2; i >= 0; --i) {
			seg[i] = seg[i * 2 + 1] + seg[i * 2 + 2];
		}
	}
	void eval(int k, int l, int r) {
		if (!laz[k]) {
			return;
		}
		if (r - l > 1) {
			laz[k * 2 + 1] += laz[k];
			laz[k * 2 + 2] += laz[k];
		}
		if (laz[k] % 2)swap(seg[k].first, seg[k].second);
		laz[k] = 0;
	}
	void flip(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = width;
		eval(k, l, r);
		if (r <= a||b <= l) {
			return;
		}
		if (a <= l&&r <= b) {
			laz[k]++;
			eval(k, l, r);
			return;
		}
		flip(a, b, k * 2 + 1, l, (l + r) / 2);
		flip(a, b, k * 2 + 2, (l + r) / 2, r);
		seg[k] = seg[k * 2 + 1] + seg[k * 2 + 2];
	}
	pair<int, int> getVal(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = width;
		eval(k, l, r);
		if (r <= a||b <= l) {
			return { 0,0 };
		}
		if (a <= l&&r <= b) {
			return seg[k];
		}
		return
			getVal(a, b, k * 2 + 1, l, (l + r) / 2) +
			getVal(a, b, k * 2 + 2, (l + r) / 2, r);
	}
};

int N, Q;
int par[123456];
vector<int>child[123456];
vector<pair<int, int>>vec;
vector<pair<int, int>>parse;

int index[123456][2];
vector<int>tour;
void euler(int x) {
	index[x][0] = tour.size();
	tour.push_back(x);
	for (int ch : child[x]) {
		euler(ch);
	}
	index[x][1] = tour.size();
	tour.push_back(x);
}

int main(void)
{
	cin >> N >> Q;
	par[0] = -1;
	for (int i = 1; i < N; ++i) {
		cin >> par[i];
		par[i]--;
		child[par[i]].push_back(i);
	}
	for (int i = 0; i < N; ++i) {
		char c;
		cin >> c;
		if (c == 'G') {
			vec.push_back({ 1,0 });
		}
		else {
			vec.push_back({ 0,1 });
		}
	}
	euler(0);
	int M = tour.size();
	for (int i = 0; i < M; ++i) {
		int val = tour[i];
		if (index[val][0] == i) {
			parse.push_back(vec[val]);
		}
		else {
			parse.push_back({ 0,0 });
		}
	}
	LazySeg lazy(M, parse);
	for (int q = 0; q < Q; ++q) {
		int vert;
		cin >> vert;
		--vert;
		lazy.flip(index[vert][0], index[vert][1]);
		auto res = lazy.getVal(index[0][0], index[0][1]);
		if (res.first > res.second) {
			cout << "broccoli" << endl;
		}
		else {
			cout << "cauliflower" << endl;
		}
	}
	return 0;
}



Compiler output:
a.cc:95:20: error: 'int index [123456][2]' redeclared as different kind of entity
   95 | int index[123456][2];
      |                    ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:7:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void euler(int)':
a.cc:98:14: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   98 |         index[x][0] = tour.size();
      |              ^
a.cc:103:14: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  103 |         index[x][1] = tour.size();
      |              ^
a.cc: In function 'int main()':
a.cc:130:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  130 |                 if (index[val][0] == i) {
      |                          ^
a.cc:142:32: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  142 |                 lazy.flip(index[vert][0], index[vert][1]);
      |                                ^
a.cc:142:48: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  142 |                 lazy.flip(index[vert][0], index[vert][1]);
      |                                                ^
a.cc:143:45: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  143 |                 auto res = lazy.getVal(index[0][0], index[0][1]);
      |                                             ^
a.cc:143:58: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  143 |                 auto res = lazy.getVal(index[0][0], index[0][1]);
      |                                                          ^