Codeforces Round 442 (Div. 2)
E
Danil and a Part-time Job
Codeforces
2000
原题
← DF →
翻译中…

Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher.

翻译中…

Danil works in a rooted tree (undirected connected acyclic graph) with $*n*$ vertices, vertex $1$ is the root of the tree. There is a room in each vertex, light can be switched on or off in each room. Danil's duties include switching light in all rooms of the subtree of the vertex. It means that if light is switched on in some room of the subtree, he should switch it off. Otherwise, he should switch it on.

翻译中…

Unfortunately (or fortunately), Danil is very lazy. He knows that his boss is not going to personally check the work. Instead, he will send Danil tasks using Workforces personal messages.

翻译中…

There are two types of tasks:

翻译中…
  1. pow v describes a task to switch lights in the subtree of vertex $*v*$.
  2. get v describes a task to count the number of rooms in the subtree of $*v*$, in which the light is turned on. Danil should send the answer to his boss using Workforces messages.
翻译中…

A subtree of vertex $*v*$ is a set of vertices for which the shortest path from them to the root passes through $*v*$. In particular, the vertex $*v*$ is in the subtree of $*v*$.

翻译中…

Danil is not going to perform his duties. He asks you to write a program, which answers the boss instead of him.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 200 000$) — the number of vertices in the tree.

翻译中…

The second line contains $*n* - 1$ space-separated integers $*p*_{2}, *p*_{3}, ..., *p*_{*n*}$ ($1 ≤ *p*_{*i*} < *i*$), where $*p*_{*i*}$ is the ancestor of vertex $*i*$.

翻译中…

The third line contains $*n*$ space-separated integers $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$ ($0 ≤ *t*_{*i*} ≤ 1$), where $*t*_{*i*}$ is $1$, if the light is turned on in vertex $*i*$ and $0$ otherwise.

翻译中…

The fourth line contains a single integer $*q*$ ($1 ≤ *q* ≤ 200 000$) — the number of tasks.

翻译中…

The next $*q*$ lines are get v or pow v ($1 ≤ *v* ≤ *n*$) — the tasks described above.

翻译中…

Output

翻译中…

For each task get v print the number of rooms in the subtree of $*v*$, in which the light is turned on.

翻译中…

Note

翻译中…

image The tree before the task pow 1.image The tree after the task pow 1.

翻译中…

样例

Input #1
4
1 1 1
1 0 0 1
9
get 1
get 2
get 3
get 4
pow 1
get 1
get 2
get 3
get 4
Output #1
2
0
0
1
2
1
1
0
InputCopy OutputCopy
题目信息
题号
877E
时间限制
2 s
内存限制
256 MB
标签
位运算
数据结构
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。