Ternary OR and Queries
InterviewTime limit4sMemory limit1024 MB
Maintain a set S of integers and, for each query x, print the largest OR_3(a, x) over all a in S, where OR_3 takes digit-wise maxima in base 3.
Problem
For two nonnegative integers and , there exist integers , , , , , , , , that satisfy all of the following conditions.
- For every integer with , .
Then the value of is uniquely determined.
Problem
Start with the set . Write a program that processes queries as follows.
- Type : update the set to .
- Type : print . In other words, for each element of the set , compute and print the largest value.
Note that the queries are cumulative.
Input
The first line contains , the number of queries.
From the second line onward, each of the next lines contains a query in the form .
At least one query of type is given. All numbers in the input are integers.
Output
For each query of type , print the answer on its own line.
Hint
For real numbers and , define .
.