#P5937. [CEOI 1999] Parity Game

[CEOI 1999] Parity Game

Description

Alice and Bob are playing a game: Bob writes a sequence consisting of 00 and 11. Alice chooses a segment of it (for example, from position 33 to position 55) and asks whether this segment contains an odd number of 11 or an even number of 11. Bob answers her question, and then Alice continues asking.

Alice wants to check Bob’s answers and determine at which answer Bob must be wrong. “Wrong” means that there exists a 0101 sequence that satisfies all answers before this one, but there does not exist any sequence that satisfies all answers before this one and also this answer.

Input Format

The first line contains an integer nn, the length of the 0101 sequence.

The second line contains an integer mm, the number of questions and answers.

Starting from the third line, each line contains one question and its answer. Each line first has two integers indicating the starting position and ending position of the segment you ask about, followed by Bob’s answer. odd means there are an odd number of 11, and even means there are an even number of 11.

Output Format

Output one line containing an integer xx, meaning that there exists a 0101 sequence satisfying answers 11 through xx, but there does not exist any sequence satisfying answers 11 through x+1x+1. If none of the answers is wrong, output the total number of answers.

10
5
1 2 even
3 4 odd
5 6 even
1 6 even
7 10 odd
3

Hint

For 100%100\% of the testdata, 1n1091 \le n \le 10^9, m5×103m \le 5 \times 10^3.

Translated by ChatGPT 5