Chef Geonggongi
Time limit2sMemory limit1024 MB
Given N values up to 511, answer Q range queries: the maximum of (XOR of a chosen subset in the range) plus the subset size.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Dynamic programming, Array
- Solved
- No attempts yet
Problem
Did you know that Geonggongi is a remarkably skilled chef? Geonggongi can make the most delicious dish from any set of ingredients.
Geonggongi has ingredients, numbered from to . Ingredient has a flavor value of . The flavor of a dish Geonggongi makes is (XOR of the flavors of all used ingredients) + (number of used ingredients).
There are queries, each given as and . For each query, find the maximum flavor of a dish Geonggongi can make using zero or more of the ingredients from the -th through the -th ( ingredients).
Input
The first line contains ().
The second line contains flavor values , separated by spaces ().
The third line contains ().
Each of the next lines contains and , separated by a space ().
Output
Print lines. For each query, print the maximum flavor of a dish Geonggongi can make, one per line.