Weighing the stones
Time limit1sMemory limit256 MB
After each ranked stone is placed on pan 1 or pan 2, report whether pan 1 is heavier under every valid weight assignment, pan 2 is, or neither is certain.
- Level
Medium7 of 10
- Topics
- Segment tree, Greedy, Prefix sum
- Solved
- No attempts yet
Problem
Seunghyun picked up stones and lined them up from the lightest to the heaviest. No two stones weigh the same. The lightest stone has rank 1, the second lightest has rank 2, and the heaviest has rank .
Seunghyun puts the stones on a two pan balance one at a time. The order of the stones and the pan each stone goes on are fixed in advance. He never tells you the actual weights, only the ranks.
Write a program that decides which way the balance tips after each stone is placed. Every weight is positive, and a stone of higher rank is heavier than a stone of lower rank. Any assignment of weights that respects those two conditions is possible. The balance tips toward pan 1 only if pan 1 is heavier under every possible assignment, and the same rule holds for pan 2. If the result depends on the assignment, or the two pans can weigh the same, the heavier side is not certain.
Input
The first line has the number of stones (). Each of the next lines has two integers () and (). is the rank of the stone being placed and is the number of the pan it goes on. All values of are different, so each rank from to appears exactly once.
Output
Print one line for each stone as it is placed. Print > if pan 1 is heavier, < if pan 2 is heavier, and ? if you cannot be sure which side is heavier.