Xorcisten
Time limit2.5sMemory limit1024 MB
After each point update to a list, find the smallest X that makes a_i XOR X non-decreasing, or -1 if no such X exists.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
Xorcisten Roxanne has a remarkable ability: she can sort lists very quickly. Given a list of integers , she instantly finds an integer such that
Here is bitwise XOR. Write both numbers in binary. Going from the least significant digit upward, write 0 if the two digits are equal and 1 otherwise. This is the same as adding the numbers in binary without carries.
All she has to do next is replace each with , and the list is sorted.
Several companies often hire Roxanne to sort their very long lists. One day, however, she discovers that her ability is gone. Your task is to write a program so that she can keep her job.
You are given a list of non-negative integers and updates , meaning that changes to . Let be the smallest non-negative integer such that the list is sorted after the first updates have been applied. Print . If no such exists, print for that value.
Input
The first line contains an integer (), the number of integers in the list.
The second line contains integers ().
The third line contains an integer (), the number of updates.
Each of the next lines contains two integers () and (), meaning that changes to .
Output
Print lines. Line (counting from 0) contains , the smallest possible that sorts the list after updates have been applied, or if no such exists.