[BZOJ4569] [Scoi2016] pyridazin Mengmeng

Meng Meng da

Subject to the effect

A number, a total of n bits, m give you a relationship, each relationship comprising \ ((L1, R1, L2, R2) \) , the representative \ (~ L1 R1 \) , \ (L2 R2 ~ \) both the counted number of such identical interval number, seeking to satisfy the condition

\ (nlogn \) range

Solution

Consider a violent practice, every time we put these intervals each corresponding point in the set and have a look and check, count the number of the last direct link block, the answer is \ (9 \ times 10 ^ {number} \)

Consider multiplier optimization, design \ (fa [x] [y ] \) representative as a starting point x, length \ (1 << y \) of this section father

For each interval after we split into several sections, finished merge several intervals, we start with the longest range to short range combined and the constant breakdown, eventually every point of the father can be determined

Finally, the same number to the number of blocks Unicom

code:

#include<bits/stdc++.h>
using namespace std;
const int mod=(1e9+7);
int fa[200010][21];
int getfa(int x,int y){
    return fa[x][y]==x?x:fa[x][y]=getfa(fa[x][y],y);
}
void merge(int x,int y,int len){
    x=getfa(x,len);
    y=getfa(y,len);
    if(x!=y)fa[x][len]=y;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<=20;++i){
        for(int j=1;j<=n;++j){
            fa[j][i]=j;
        }
    }
    for(int i=1;i<=m;++i){
        int l1,r1,l2,r2;
        scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
        int x=(r1-l1+1);
        for(int j=20;j>=0;--j){
            if(x&(1<<j)){
                merge(l1,l2,j);
                l1+=(1<<j),l2+=(1<<j);
            }
        }
    }
    for(int i=20;i>=1;--i){
        for(int j=1;j+(1<<i)-1<=n;++j){
            merge(j,getfa(j,i),i-1);
            merge(j+(1<<i-1),getfa(j,i)+(1<<i-1),i-1);
        }
    }
    int ans=9;
    int num=0;
    for(int i=1;i<=n;++i){
        if(fa[i][0]==i){
            num++;
            if(num>1){
                ans=(ans*1ll*10)%mod;
            }
        }
    }
    printf("%d\n",ans);
}

Guess you like

Origin www.cnblogs.com/youddjxd/p/11616126.html