xsy 2412 BZOJ4569 [] [] Meng Meng da Scoi2016

Description

 

Description

    A large number of length n, with S1S2S3 ... Sn, where Si represents the i-th bit, the highest bit of the Sl, tell you some restrictions, each condition is represented as four numbers, l1, r1 , l2, r2, i.e. the length of two identical sections, a substring Sl1Sl1 + 1Sl1 + 2 ... Sr1 and Sl2Sl2 + 1Sl2 + 2 ... Sr2 identical. N = 6 for example, a restriction l1 = 1, r1 = 3, l2 = 4, r2 = 6, then the conditions are satisfied 123123,351351, but 12012,131141 condition is not satisfied, the length of the former is not the number 6, the second place and fifth place were different. More than a few asked how many meet all the conditions.

Input

    The first two row n and m, respectively represent the length of the large numbers, and the number of constraints. Next m-th row, for i-th row, the number 4 li1, ri1, li2, ri2, two sections respectively corresponding to the constraint.

    1≤n≤10 ^ 5,1≤m≤10 ^ 5,1≤li1, ri1, li2, ri2≤n; and ensure ri1-li1 = ri2-li2.

Output

    A number representing the length of all conditions are met and the number of large numbers n, the answer may be large, the output result of the answer mode 10 ^ 7 + 9 can.

Sample Input

4 2
1 2 3 4
3 3 3 3

Sample Output

90

Problem solution ideas
A first set array f [i] [j], i denotes the number of starts from j rearwardly from the number of power of 2 and F [i] [j] th power of the number 2 starts rearwardly same number j.
For each of the two equal sections, we first use the power multiplier classifies them small segment of a plurality of length 2, then each of the small pieces and combined so as to set the check.
The time complexity of this operation is O (nlogn).
Then start from the maximum power of 2, if the f [i] [j] = k, it is converted to combined f [i] [j-1], k, and f [i + 2 ^ (j-1)] [j], k.
The time complexity of this operation is O (nlogn) a.
Finally, a statistical s, represents f [i] [0] = the number i of the i.
Finally, the power is obtained by flash 9 * (10 ^ (s-1)) to (can not begin with 0) (in fact, may be multiplied without speed)
The time complexity is O (n) a.
Therefore, the overall time complexity of O (nlogn)
 
#include<iostream>
#include<cstdio>
using namespace std;
long long n,m,l1,l2,r1,r2,f[100001][21],v[21],cnt=-1,fx,fy,s,ans=1,mod=1000000007;
long long fa(long long id,long long a){
    if(f[a][id]!=a)f[a][id]=fa(id,f[a][id]);
    return f[a][id];
}
long long find(long long a){
    s=10ll;
    while(a>0){
        if(a%2ll)ans=(ans*s)%mod;
        s=(s*s)%mod;
        a=a/2ll;
    }
}
void merge(long long id,long long x,long long y){
    fx=fa(id,x);
    fy=fa(id,y);
    if(fx!=fy)f[fx][id]=fy;
}
int main(){
    v[0]=1;
    for(long long i=1;i<=20;i++)v[i]=v[i-1]*2;
    scanf("%lld%lld",&n,&m);
    for(long long i=1;i<=n;i++)for(long long j=0;j<=20;j++)f[i][j]=i;
    for(long long i=1;i<=m;i++){
        scanf("%lld%lld%lld%lld",&l1,&r1,&l2,&r2);
        for(long long j=20;j>=0;j--){
            if(v[j]<=r1-l1+1){
                merge(j,l1,l2);
                l1=l1+v[j];
                l2=l2+v[j];
            }
        }
    }
    for(long long i=20;i;i--){
        for(long long x=1;x+v[i]-1<=n;x++){
            s=fa(i,x);
            merge(i-1,x,s);
            merge(i-1,x+v[i-1],s+v[i-1]);
    for(long long i=1;i<=n;i ++) { 
        s = F (0, i);
        }
    } 
        If (i == s) cnt ++; 
    } 
    Find (cnt); 
    9LL years = years *; 
    years = year mod%; 
    printf ( "% lld \ n", year); 
}

  

 

Guess you like

Origin www.cnblogs.com/ez-syh/p/11615488.html