标签:queue owb each int begin fine code cas specific
InputThere are several test cases in the input.
Each test case begin with two integers N (1<=N<=10000000) and M (0<=M<=1000) indicating the length of the code system and the number of legal operations.
Then M lines follows. Each line contains two integer L and R (1<=L<=R<=N), means an interval [L, R], each time you can choose one interval, move all of the wheels in this interval up.
The input terminates by end of file marker.
OutputFor each test case, output the answer mod 1000000007Sample Input
1 1 1 1 2 1 1 2
Sample Output
1 26
题解:先放一放
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <cstdlib> 7 #include <iomanip> 8 #include <cmath> 9 #include <ctime> 10 #include <map> 11 #include <set> 12 #include <queue> 13 using namespace std; 14 #define lowbit(x) (x&(-x)) 15 #define max(x,y) (x>y?x:y) 16 #define min(x,y) (x<y?x:y) 17 #define MAX 100000000000000000 18 #define MOD 1000000007 19 #define pi acos(-1.0) 20 #define ei exp(1) 21 #define PI 3.141592653589793238462 22 #define INF 0x3f3f3f3f3f 23 #define mem(a) (memset(a,0,sizeof(a))) 24 typedef long long ll; 25 ll gcd(ll a,ll b){ 26 return b?gcd(b,a%b):a; 27 } 28 bool cmp(int x,int y) 29 { 30 return x>y; 31 } 32 const int N=10000005; 33 const int mod=1e9+7; 34 int f[N]; 35 int find1(int x) {return x==f[x]?x:f[x]=find1(f[x]);}; 36 int Union(int x,int y) 37 { 38 x=find1(x),y=find1(y); 39 if(x==y) return 0; 40 return f[x]=y,1; 41 } 42 ll multi(int x) 43 { 44 ll ans=1,tmp=26; 45 while(x){ 46 if(x&1) ans=(ans*tmp)%mod; 47 tmp=(tmp*tmp)%mod; 48 x>>=1; 49 } 50 return ans; 51 } 52 int main() 53 { 54 int n,m; 55 while(~scanf("%d%d",&n,&m)){ 56 for(int i=1;i<=n+2;i++) f[i]=i; 57 int a,b,ans=0; 58 for(int i=0;i<m;i++){ 59 scanf("%d%d",&a,&b); 60 ans+=Union(a,b+1); 61 } 62 printf("%lld\n",power(n-ans)); 63 } 64 return 0; 65 }
标签:queue owb each int begin fine code cas specific
原文地址:http://www.cnblogs.com/shixinzei/p/7295645.html