1445: Parity 奇偶
题目描述
Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous subsequence (for example the subsequence from the third to the fifth digit inclusively) and ask him, whether this subsequence contains even or odd number of ones. Your friend answers your question and you can ask him about another subsequence and so on.
偶尔你跟朋友玩以下的游戏:你的朋友写下一串包含1和0的数串让你猜,你可以从中选择一个连续的子串(例如其中的第3到第5个数字)问他,该子串中包含了奇数个还是偶数个1,他会回答你的问题,然后你可以问其他子串,等等。
Problem
Your task is to guess the entire sequence of numbers. You suspect some of your friend's answers may not be correct and you want to convict him of falsehood. Thus you have decided to write a program to help you in this matter. The program will receive a series of your questions together with the answers you have received from your friend. The aim of this program is to find the first answer which is provably wrong, i.e. that there exists a sequence satisfying answers to all the previous questions, but no such sequence satisfies this answer.
你的任务是猜出完整的子串。你怀疑你的朋友的答案可能有错,你想质疑他的错误。 所以要写这个程序帮忙验证。程序接受一系列你的问题以及你朋友给出的答案。程序的目标是找出错误的第一个答案,也就是某一子串满足先前的所有答案,而不满足当前这个答案。
输入
Input contains a series of tests. The first line of each test contains one number, which is the length of the sequence of zeroes and ones. This length is less or equal to 1000000000. In the second line, there is one positive integer which is the number of questions asked and answers to them. The number of questions and answers is less or equal to 5000. The remaining lines specify questions and answers. Each line contains one question and the answer to this question: two integers (the position of the first and last digit in the chosen subsequence) and one word which is either `even' or `odd' (the answer, i.e. the parity of the number of ones in the chosen subsequence, where `even' means an even number of ones and `odd' means an odd number). The file is ended with a line containing -1.
输入一系列的点。 首行为整个数串的长度,小于或等于1000000000。第二行为一个正整数,表示问题及答案数,小于或等于5000。之后每行表示问题及答案。格式:2个整数(即子串的第一个及最后一个数位),答案为一个单词:'even'(偶),或'odd'(奇),即选择的子串中1的个数是奇数个,则答案为odd,否则为even。最后以-1结束。
输出
Each line of output containing one integer X. Number X says that there exists a sequence of zeroes and ones satisfying first X parity conditions, but there exists none satisfying X+1 conditions. If there exists a sequence of zeroes and ones satisfying all the given conditions, then number X should be the number of all the questions asked.
输出x,x表示存在01数串满足前x个奇偶条件,但不满足第x+1个条件。。假如存在满足所有条件的01串,则输出的数字为问题总数。
样例输入 复制
10
5
1 2 even
3 4 odd
5 6 even
1 6 even
7 10 odd
-1
样例输出 复制
3