题解:计算出所有可以操作的区间,留下不可操作区间求26的幂次即可,注意直接合并区间端点可能会出现一些问题,所以将右端点加一:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 |
#include <cstdio> #include <iostream>using
namespace std; const
int mod=1000000007; long
long t; int f[10000010]; int sf(int
x){return
x==f[x]?x:f[x]=sf(f[x]);} int Union(int
x,int y){ x=sf(x),y=sf(y); if(x==y)return
0; f[x]=y; return
1; } long
long power(int
x){ if(x==0)return
1; long
long t=power(x/2); t=t*t%mod; if(x%2==1)t=t*26%mod; return
t; } int
main(){ int
m,n,a,b; while(scanf("%d%d",&n,&m)!=EOF){ for(int
i=1;i<=n+2;i++)f[i]=i; int
ans=0; while(m--){ scanf("%d%d",&a,&b); ans+=Union(a,b+1); } cout<<power(n-ans)<<endl; } } |
原文:http://www.cnblogs.com/forever97/p/3550477.html