hdu 6399 City Development

vjudge

Reading may have come in the same \ (n_i \) , but at the same \ (n_i \) , only the last one is useful, so the other to shrink up, these shrink after the \ (n \) number will not more than 19

The answer can be found in a city is a linear combination of all the initial weights of the city, then for \ (x \) , and other \ (x \) the same gcd then transfer the same point transfer coefficient is the same depth as the depth is gcd essentially the same

Consider then the transfer matrix configuration, \ (A_ {I, J} \) represents gcd depth \ (I \) was transferred to a depth of \ (J \) the number of programs, then the answer is \ (ans_x = \ sum_ {i . 1} ^ {n-= D_X {}} _ {F ^ T \ gcd (X, I), m} \) (of course, to be counted with the same gcd)

Consider \ (i \ neq j \) cases, this time regardless of which point transfer coefficient are \ (P _ {\ min (I, J)} \) , then also multiplied by gcd depth \ (J \) points, ie \ (p _ {\ min ( i, j)} (n_j-n_ {j + 1}) \)

Then \ (i = j \) in the case can be found from a depth of \ (I \) point to the same point depth, lca has a depth between the two points \ (m, m-1, m- ... I 2 \) . for \ (> i \) portions, and these are \ (i \ neq j \) similar, i.e., \ (\ sum_ {k = i + 1} ^ {m} p_ { K} (n_k-of N_ {K +. 1}) \) . However, if the \ (= I \) , then the number of points that can be reached is much \ (n_ {i + 1} \) of this part is to \ (X \) GCD depth \ (> i \) portion, so this is divided into \ (p_ {i} (n_i -2n_ {i + 1}) \)

//以下是在laji hduPE的代码
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db long double

using namespace std;
const int N=3e5+10,mod=998244353;
LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
};
int n,m,d[N],c[N];
LL T,a[N];
struct matrix
{
    int a[22][22];
    matrix(){memset(a,0,sizeof(a));}
    matrix operator * (const matrix &bb) const
    {
        matrix an;
        for(int i=0;i<=m;++i)
            for(int j=0;j<=m;++j)
            {
                LL nw=0;
                for(int k=0;k<=m;++k) nw+=1ll*a[i][k]*bb.a[k][j]%mod;
                an.a[i][j]=nw%mod;
            }
        return an;
    }
    matrix operator ^ (const LL &bb) const
    {
        matrix an,a=*this;
        for(int i=0;i<=m;++i) an.a[i][i]=1;
        LL b=bb;
        while(b)
        {
            if(b&1) an=an*a;
            a=a*a,b>>=1;
        }
        return an;
    }
}bb;

int main()
{
    int K=rd();
    while(K--)
    {
        memset(bb.a,0,sizeof(bb.a));
        n=rd(),m=rd(),T=rd();
        d[0]=n;
        for(int i=1;i<=m;++i) d[i]=rd();
        d[m+1]=0;
        for(int i=1;i<=n;++i) a[i]=a[i-1]+rd();
        for(int i=0;i<=m;++i) c[i]=rd();
        int nn=m;
        m=-1;
        for(int i=0;i<=nn;++i)
            if(d[i]!=d[i+1]) d[++m]=d[i],c[m]=c[i];
        d[m+1]=0;
        for(int i=0;i<=m;++i)
            for(int j=0;j<=m;++j)
            {
                if(i==j)
                {
                    for(int k=m;k>i;--k)
                        bb.a[i][j]=(bb.a[i][j]+1ll*c[k]*(d[k]-d[k+1])%mod)%mod;
                    bb.a[i][j]=(bb.a[i][j]+1ll*c[i]*(d[i]-d[i+1]-d[i+1])%mod)%mod;
                }
                else bb.a[i][j]=1ll*c[min(i,j)]*(d[j]-d[j+1])%mod;
            }
        bb=bb^T;
        for(int i=1;i<=n;++i)
        {
            int ll=2,rr=1,an=0;
            for(int j=m;~j;--j)
            {
                int r=(i+d[j]-1)/d[j]*d[j],l=r-d[j]+1;
                an=(an+((a[r]-a[l-1])-(a[rr]-a[ll-1]))%mod*bb.a[j][m]%mod)%mod;
                ll=l,rr=r;
            }
            printf("%d",an);
            if(i<n) putchar(' ');
        }
        if(K) puts("");
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/smyjr/p/11574185.html