Urgent Training Day 1 (2)

Source: Internet
Author: User

The interval of mushroom
"Title description"
The mushroom has a line number and is initially all 0. Now Mushroom has a M interval [l,r], and he wants to get a new sequence with the following operations.
Select an interval [s,t] from a given interval of M to flip all the corresponding elements in the interval. (0 change to 0)
Please tell mushroom how many bands he can get. (Die 10^9+7)
"Input Format"
The first line consists of two integer n,m. Represents the number of N and M intervals.
The next M-line is the indicated interval.
"Output Format"
An integer that represents the number of intervals that can be obtained.
"Sample Input"
3 3
1 1
2 2
3 3
"Sample Output"
8
"Data Range"
For 30% of data, n,m<=20
For 60% of data, n,m<=100
For 100% of data, n,m<=100000

"Sample Interpretation"
Each location can be modified individually, so there are 8 possibilities.

Magic Solution, thinking: remove some of the other intervals can be covered out of his interval (the interval is considered invalid) the last effective interval number is power, ans=2^ (number of sides)

How to maintain whether the interval is overwritten, here is a very magical and check the set procedure, because L can be equal to r so consider panning left interval one (the answer does not change)
Each reading is judged by the father of both ends of the point if Father is the same, it means that the interval can be covered by the previously occurring interval (which is equivalent).

#include <iostream>#include<cstring>#include<cstdio>#include<map>#include<vector>#include<algorithm>#include<queue>using namespacestd;Const intmax=1000005;Const intMod=1000000000+7;intn,m,ans=1;intFa[max];intFINDFA (intk) { if(fa[k]!=k)returnfa[k]=Findfa (Fa[k]); returnfa[k];}intMain () {Cin>>n>>m; for(intI=0; i<=n;i++) Fa[i]=i; for(intI=1; i<=m;i++) { intx, y; scanf ("%d%d",&x,&y); intF1=FINDFA (x1); intF2=Findfa (y); if(f1!=F2) {FA[F1]=F2; Ans=ans*2%MOD; }} cout<<ans;}

Urgent Training Day 1 (2)

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.