Guessing Game
Time limit1sMemory limit128 MB
Find the largest prefix of interval parity answers that stays consistent with some 0/1 sequence of length one billion.
- Level
Medium7 of 10
- Topics
- Union-find, Prefix sum, Hash map
- Solved
- No attempts yet
Problem
Byteman and Bitman play the following game. Bitman secretly writes down a sequence of zeros and ones. Byteman's goal is to guess this sequence.
Byteman repeatedly asks Bitman questions of the form:
Is the sum of the subsequence that begins at the -th element and ends at the -th element of your sequence even or odd?
After playing for a while, Byteman began to suspect that Bitman was answering dishonestly. He would like to know how many of his questions, counting from the first, can still be answered consistently.
Write a program that computes the greatest number for which there exists a sequence of zeros and ones consistent with Bitman's answers to the first questions.
Input
The first line contains one integer (), the number of Byteman's questions.
Each of the following lines describes one question together with Bitman's answer as three integers , , and (, ) separated by single spaces. Here and are the positions of the first and last elements of the subsequence in that question. means the answer was that the sum is even, and means it is odd.
Output
Output a single integer : the greatest value such that a sequence of zeros and ones consistent with the first answers exists.