9.28 csp-s analog test 54 x + y + z

T1 x

Quality factor is determined for each number of disjoint-set to maintain the same number of factors, the last block to see a total number of China Unicom, $ ans = 2 ^ {cnt} -2 $

However, direct decomposition will $ T $, Å sieve is a good choice, or with each only have a maximum number of greater than $ \ sqrt {n} $ prime factors, the number of voxels within the wire mesh $ $ 1e6, each just enumerate $ 1e3 $ prime factors on the line, complexity can also be in the past

#include<iostream>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<cstring>
#include<vector>
#define ll long long
#define mod 1000000007
using namespace std;
ll T,n,ans,a[100100],prime[100100],fa[100100],num,pr[1001000],tot;
bitset<100100>vis;
bitset<1001000>v;
vector<int>ve[1001000];
ll read()
{
    ll aa=0,bb=1;char cc=getchar();
    while(cc>'9'||cc<'0'){if(cc=='-') bb=-1;cc=getchar();}
    while(cc>='0'&&cc<='9'){aa=(aa<<3)+(aa<<1)+(cc^'0');cc=getchar();}
    return aa*bb;
}
ll quick(ll x,ll p)
{
    ll as=1;
    while(p){
        if(p&1) as=as*x%mod;
        x=x*x%mod;
        p>>=1;
    }
    return as;
}
ll find(ll x)
{
    if(x!=fa[x]) fa[x]=find(fa[x]);
    return fa[x];
}
void init()
{
    for(int i=2;i<=1000000;i++){
        if(v[i]) continue;prime[++tot]=i;
        for(int j=i;j<=1000000;j+=i){
            v[j]=1;
            ve[j].push_back(i);
        }
    }
}
int main()
{
    T=read();init();
    while(T--){
        n=read();ans=0;num=0;vis.reset();memset(pr,0,sizeof(pr));
        for(int i=1;i<=n;i++) a[i]=read(),fa[i]=i;
        for(int i=1;i<=n;i++){
            for(int j=0;j<ve[a[i]].size();j++){
                if(pr[ve[a[i]][j]]) fa[find(i)]=find(pr[ve[a[i]][j]]);
                else pr[ve[a[i]][j]]=i;
            }
        }
        for(int i=1;i<=n;i++){
            int f=find(i);
            if(force [f]) to [p] = 1 , whether ++ ; 
        } 
        Ans = (Quick ( 2 , num) - 2 + mod)% mod; 
        printf ( " % lid \ n " , ans); 
    } 
    Return  0 ; 
}
x

 

 

T2 and

$ Bitset $ flexible application

Thinking is started $ 2 ^ {20} $ enumeration state, memory search, $ f [i] [sta] $ indicates whether out of the starting state STA $ i $ from point (a first state represents the length) , but no less open space, the time could not carry

So change strategy, record only half of the state, the last enumerated intermediate point

$ F [i] [sta] [j] $ expresses a starting point of $ i $, endpoint $ j $, $ intermediate state STA $ feasibility

Need to enumerate a normal point, a state, and a point in the enumeration, enumeration and then a second point with a point edge is connected, if the STA $ $ state between the first two points feasible, then the first point between the third point and the $ sta << 1 | h [i] .w $ is feasible

However, the time is clearly not good

$ Bitset $ comes in handy, if $ sta $ state between two points is feasible, then even the first point and the end point of this state and the second point of the side is the same, so when the construction side with $ bitset $ adjacency table, plus a one-dimensional representation is $ 0 $ or $ 1 $, $ bitset $ merger on the line, and finally need to enumerate the state and the mid-point to see if the state makes up

There is to represent the length of each state in the first place, otherwise $ 01 $ 001 $ and $ state is hard to tell. For $ 01 $ string is odd properly handle $ len / 2 $ and $ len / 2 + 1 $ the relationship between the length of the two

#include<iostream>
#include<cstdio>
#include<cstring>
#include<bitset>
using namespace std;
int n,m,d,ans;
bitset<99>f[99][(1<<12)+5],bt[2][99];
int read()
{
    int aa=0,bb=1;char cc=getchar();
    while(cc>'9'||cc<'0'){if(cc=='-') bb=-1;cc=getchar();}
    while(cc>='0'&&cc<='9'){aa=(aa<<3)+(aa<<1)+(cc^'0');cc=getchar();}
    return aa*bb;
}
int main()
{
    n=read();m=read();d=read();int dd=d/2,dis=d-dd;
    int u,v,c;
    for(int i=1;i<=m;i++){
        u=read();v=read();c=read();
        bt[c][u][v]=1;bt[c][v][u]=1;
        f[u][c|2][v]=1;f[v][c|2][u]=1;
    }
    for(int i=1;i<=n;i++){
        for(int sta=2;sta<(1<<(dis+1));sta++){
            for(int j=1;j<=n;j++){
                if(!f[i][sta][j]) continue;
                f[i][sta<<1|1]|=bt[1][j];
                f[i][sta<<1|0]|=bt[0][j];
            }
        }
    }
    for(int i=0;i<(1<<d);i++){
        bool flag=0;
        for(int j=1;j<=n;j++){
            if(f[1][i>>dd|(1<<dis)][j]&&f[j][i&((1<<dd)-1)|(1<<dd)].count()){
                flag=1;
                break;
            }
        }
        if(!flag&&dd!=dis){
            for(int j=1;j<=n;j++){
                if(f[1][i>>dis|(1<<dd)][j]&&f[j][i&((1<<dis)-1)|(1<<dis)].count()){
                    flag=1;
                    break;
                }
            }
        }
        ans+=flag;
    }
    printf("%d\n",ans);
    return 0;
}
Y

 

 

T3 z

The cushions

 

 

Do not want to retire should be at ease

Guess you like

Origin www.cnblogs.com/jrf123/p/11611362.html