PIB '20 P3 - Rulebreaker
View as PDFJohn has an ongoing contest with some of his friends. The problem is that they constantly find loopholes to exploit John's contest, so John has to make some new rules, but sometimes John's friends find loopholes to those rules. Then, he'll make new rules to overrule those rules.
In essence, John has a list of rules, each being able to do two operations:
- Create a new rule.
 - Create a new rule to not follow the previous rule that was created.
 
After a while, John's friends get confused about which rule to follow, and so they come to ask you for help. They will give you  queries of one of the following forms:
1Create a new rule. It is guaranteed the first query will always be of this type.2Create a new rule to not follow the previous rule that was created.3 xOutput whether John's friends should follow therule that was created or not. It is guaranteed
, where
is the number of rules that has been created so far.
is one indexed.
Note: Rules that are created later are given higher priority in determining which rules to follow.
For example, if the following queries were given:
- Create a rule.
 - Create a rule to not follow the previous rule.
 - Create a rule.
 - Create a rule to not follow the previous rule.
 
In this case, rules  and 
 would not be followed and rules 
 and 
 will be followed.
Note: Python users are recommended to use CPython over PyPy and add the following line to the top of their solution for performance purposes: input = sys.stdin.readline.
Input Specification
The first line will contain the integer  
, the number of queries.
The next  lines will each contain a query as defined above.
Output Specification
For each type 3 query, output 1 if John's friends should follow rule  and 
0 otherwise on its own line.
Subtasks
Subtask 1 [19%]
Subtask 2 [81%]
No additional constraints.
Sample Input for Subtask 1
5
1
2
3 1
2
3 1
Sample Output for Subtask 1
0
1
Explanation for Sample for Subtask 1
- Create a new rule, indexed 
1. - Create a new rule, indexed 
2, to not follow the previous rule (rule1). Currently, John's friends should follow rule2and not follow rule1. - Query if rule 
1should be followed - it should not. Therefore,0is outputted. - Create a new rule, indexed 
3, to not follow the previous rule (rule2). This means John's friends should follow rules1and3but not rule2. - Query if rule 
1should be followed - it should. Therefore,1is outputted. 
Sample Input for Subtask 2
101
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3 2
3 3
Sample Output for Subtask 2
0
1
Comments