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)