Sequence and Queries 38
InterviewTime limit2sMemory limit256 MB
Maintain a sequence under append, delete-one-copy, and report running sum and XOR of all elements.
- Level
Medium4 of 10
- Topics
- Hash map, Implementation, Math, Simulation
- Solved
- No attempts yet
Problem
There is an array A that initially contains a single 0. You must process the following queries on it.
1 x: appendxto the back of A.2 x: removexfrom A. If A contains two or more copies ofx, remove only the frontmost one. This query is only given when A containsx.3: print the sum of all elements in A.4: print the XOR of all elements in A.
Input
The first line gives the number of queries M. Each of the next M lines gives one query.
Output
For every query of type 3 or type 4, print the answer on its own line.
Constraints
- 1 ≤ M ≤ 500 000
- 1 ≤ x ≤ 1 000 000 000
- At least one query of type 3 or type 4 is given.