BZOJ4625 [BJOI2016] minimum cut crystal

Description of the meaning of problems

You give a three-dimensional coordinate system, the coordinate system \ ((x_i + y_i + z_i ) \ bmod 3 = 0 \) has an energy source within the site. Given \ (n-\) points comprising energy value \ (C_i \) crystal, if a power source is located on the crystal, the crystal would increase the energy value \ (10 \% \) .

There are two kinds of crystal resonance cases, one three adjacent crystal resonator, the second is as a two crystal length \ (2 \) at both ends of the line segment, the midpoint of the line segment and the energy source.

You can blow up some of the crystal, the maximum energy value remaining after Will not crystal resonance.

practice

For \ ((x_i + y_i + z_i ) \ bmod 3 \ not = 0 \) black and white stain point, if the dot of black or white around a source of energy exist, then there must constitute a resonator, shown in FIG.

1.png

So we can put \ (\ bmod 3 \) three kinds of points in the meaning of each split point. Consider, for each resonance, use a minimum cost damage, obviously a minimum cut model. Each point of the split point, the right side of the crystal energy value \ (C_i \) . Then source connected \ (1 \) point \ (1 \) connected \ (0 \) , \ (0 \) connected \ (2 \) , \ (2 \) connected meeting point, the answer to the total crystal energy \ (\ sum c_i \) Save the maximum flow. Here are code implements:

const int inf=1e9;
inline void link(int a,int b,int c)
{
    add_edge(S,a<<1,inf);add_edge(a<<1|1,b<<1,inf);
    add_edge(b<<1|1,c<<1,inf);add_edge(c<<1|1,T,inf);
}

We then use a structure to represent each point, the \ ((x_i, y_i, z_i ) \) is converted to \ ((x_i-z_i, y_i-z_i) \) , the structure for a vector of sequestering heavy upload >and +budget operators, with a mapto operate on a vector, the problem is over.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register int
#define db double
#define ak *
#define in inline
in char getch()
{
    static char buf[1<<12],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<!2,stdin),p1==p2)?EOF:*p1++;
}
char qwq;
#define gc() getch()
in ll read(re p=0)
{
    ll cz=0,ioi=1;qwq=gc();
    while(qwq<'0'||qwq>'9') ioi=qwq=='-'?~ioi+1:1,qwq=gc();
    while(qwq>='0'&&qwq<='9') 
    {
        cz=(cz<<3)+(cz<<1)+(qwq^48),qwq=gc();
        if(p) cz%=p;
    }
    return cz ak ioi;
}
const int p=998244353;
ll ans;
ll n,tot,m,k,inv[20000005],prime[5000005],vis[20000005],a[20000005],b[20000005];
inline ll qpow(ll x,ll y,ll z=1)
{
    x%=p;
    for(;y;y>>=1,x=(x*x)%p) z=(y&1)?(z*x)%p:z;
    return z;
}
inline ll get_inv(ll x) {return qpow(x,p-2);}
inline void get_sum(re len)
{
    a[1]=1;
    for(re i=2;i<=len;i++)
    {
        if(!vis[i]) prime[++prime[0]]=i,a[i]=qpow(i,k);
        for(re j=1;j<=prime[0];j++)
        {
            if(i*prime[j]>len) break;
            vis[i*prime[j]]=1;a[i*prime[j]]=a[i]*a[prime[j]]%p;
            if(i%prime[j]==0) break;
        }
    }
}
in ll lagrange(ll n)
{
    if(n<=tot) return b[n];
    ll nw=0,tmp=1;a[tot+1]=1;
    for(re i=tot;i;i--) a[i]=a[i+1]*(n-i)%p;
    for(re i=1;i<=tot;i++)
    {
        ll t=a[i+1]*inv[i-1]%p*inv[tot-i]%p;
        ll res=((tot-i)&1)?-1:1;
        ans=(ans+1ll*b[i]*tmp%p*t%p*res%p)%p;
        tmp=tmp*(n-i)%p;
    }
    return ans;
}
int main()
{
    n=read(p);k=read();tot=k+3;
    inv[0]=inv[1]=1;
    for(re i=2;i<=tot;i++) inv[i]=(ll)(p-p/i)*inv[p%i]%p;
    for(re i=2;i<=tot;i++) inv[i]=inv[i]*inv[i-1]%p;
    if(k==1) return printf("%lld",(n-1)*(n+1)%p),0;
    if(n<=1e5)
    {
        get_sum(n+n-1);
        for(re i=2;i<=n+n-1;i++)
        {
            ll t=(n-abs(n+1-i))/2;
            cout<<a[i]<<" ";
            ans+=a[i]*t%p;ans=(ans%p+p)%p;
        }
    }
    else
    {
        get_sum(tot*2+1);
        for(re i=1;i<=tot<<1;i++) a[i]=(a[i]+a[i-1])%p;
        for(re i=1;i<=tot;i++) b[i]=((b[i-1]+a[2*i-1])%p-a[i])%p;
        ans=(lagrange(n)%p+p)%p;
    }
    printf("%lld\n",ans*(n-1)%p*get_inv(1ll*n*(n-1)/2)%p);
}

Guess you like

Origin www.cnblogs.com/disangan233/p/11140147.html