Wedding
InterviewTime limit2sMemory limit1024 MB
After each arrival, departure, or XOR dance, the task is to print the total sociability of the fairies currently present.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Implementation
- Solved
- No attempts yet
Statement
Philip and Aurora are getting married today, and all the fairies of the Murky Marshes are invited. Aurora got a little bored and decided to watch how the fairies interact.
At the start, fairies are at the wedding, and Aurora numbered them from to . Fairy number has a sociability , a non-negative integer.
During the observation, Aurora saw interesting moments. At the -th moment, one of three events happened:
- A fairy with sociability arrives. Aurora gives her the first number that has never been used before. The first arriving fairy gets number , the next one gets , and so on.
- The fairy with number leaves the wedding.
- A dance with expressiveness , a non-negative integer, is announced. After the dance, every fairy's sociability changes. If a fairy had sociability before the dance, it becomes , the bitwise XOR of and .
Aurora wants to know how intensely the fairies interact. After each event, she wants the total sociability of all fairies currently at the wedding. Help Aurora with this task.
Input
The first line contains two integers and , the number of fairies initially at the wedding and the number of moments ().
The second line contains integers , the sociability values of the initial fairies ().
Each of the next lines starts with an integer , the event type ().
- If , the line contains one more integer , the sociability of the arriving fairy (). The arriving fairy gets the first number never used before.
- If , the line contains one more integer , meaning the fairy with number leaves the wedding. It is guaranteed that this fairy is present at that moment.
- If , the line contains one more integer , the expressiveness of the dance ().
Output
After each event, print the total sociability of all fairies currently at the wedding.