VijosP1112: Chubby Odd Couple

Source: Internet
Author: User

Describe

Huyichen and Xuzhenyi are playing a game: he writes a sequence consisting of 0 and 1.

Huyichen selected one of the sections (3rd to 5th) and asked him if there was an odd number of 1
Or even a few 1. Xuzhenyi answer your question, and then huyichen continue to ask.

Xuzhenyi is likely to be lying. Huyichen to check Xuzhenyi's answer, pointing out that the first few answers in Xuzhenyi must be problematic.

The problem is that there is a 01 sequence that satisfies all the answers before the answer, and there is no sequence
Meet all the answers and this answer before the answer.

Format input Format

The 1th line, an integer, is the length of this 01 sequence (<=1000000000)
The 2nd line, an integer, is the number of questions and answers.

Line 3rd starts with the question and the answer,
Each line is preceded by two integers, indicating the start and end positions of the segment you are inquiring about.

Then there was Xuzhenyi's answer. Odd indicates that there are an odd number of 1,even that have an even number of 1.

Output format

The output line, a number x, indicates that there is a 01 sequence that satisfies the 1th to the X answer,
But there is no sequence that satisfies the 1th to x+1 answer. If all the answers are okay, you output
The number of all answers.

Input:

10
5
1 2 Even
3 4 Odd
5 6 Even
1 6 Even
7 Odd

Output

3

Idea: l R even is equivalent to the sequence parity of 0-L-1 and 0-r. Odd equivalent for odd pages is the opposite of parity. When X is hashed, its position in the hash array represents its hash value.

#include <cstdio>#include<cstring>using namespacestd;Const intMod=1000007;intHash[mod];intPar[mod+MOD];intHASH (intx) {    intt=x%MOD;  while(hash[t]!=-1&&hash[t]!=x) T= (t+1)%MOD; Hash[t]=x; returnt;}voidPrep () { for(intI=0; i<mod+mod;i++) {Par[i]=i; }}intFndintx) {    if(x==Par[x])returnx; returnpar[x]=fnd (par[x]);}voidUniteintXinty) {    intA=fnd (x); intb=fnd (y); Par[a]=b;}BOOLSame (intXinty) {    returnFND (x) = =fnd (y);}intMain () {memset (Hash,-1,sizeof(Hash)); intn,m; scanf ("%d%d",&n,&m); intres=m;    Prep ();  for(intI=0; i<m;i++)    {        intL,r; Chars[5]; scanf ("%d%d%s",&l,&r,s); if(res!=m)Continue; intA=hash (l1); intb=HASH (R); if(s[0]=='e')        {            if(Same (a,b+MOD)) {Res=i;            } unite (A, b); Unite (a+mod,b+MOD); }        Else        {            if(Same (A, b)) {res=i; } unite (A, B+MOD); Unite (a+mod,b); }} printf ("%d\n", RES); return 0;} 

VijosP1112: Chubby Odd Couple

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.