/*题目链接*/
题意:对给定的N个数进行T次操作,每次操作依次更改所有的数,更改的定义如下:对于第i个数,取上次操作后除第i个数以外的N-1个数并求和。
当N=3时:读入(C1,C2,C3)
C1
C2
C3
T=0 1C1+0C2+0C3 0C1+1C2+0C3 0C1+0C2+1C3 T=1 0C1+1C2+1C3 1C1+0C2+1C3 1C1+1C2+0C3 T=2 2C1+1C2+1C3 1C1+2C2+1C3 1C1+1C2+2C3 T=3 2C1+3C2+3C3 3C1+2C2+3C3 3C1+3C2+2C3 T=4 6C1+5C2+5C3 5C1+6C2+5C3 5C1+5C2+6C3……
题目分析:
当N=3时,对于C1的偶数操作来说,运算的结果是(1,0,0)、(2,1,1)、(6,5,5)......,C1项的系数比其余项多一。奇数操作的结果是(0,1,1)、(2,3,3)......,C1项比其余项少一。对于C2、C3等同理。
现在取出(1,0,2,2,6......)作为数列a(a0 = 1),易得
。由于T<1414213562,递推求解必然超时,所以需要求出通项公式,因为该递推式是
类型的,所以我们求通项的方法是等式两边同除以
,之后经过移项->累项相消->等比数列求和化简后可得
。这是N=3的通项,扩展到N的情况:
求出公式后,我们可以用快速幂在时限内得到它的值。求值的时候注意两点:1、除法变化为它的逆元 2、遇到结果可能为负数的时候加上模。
之后我们分奇偶进行讨论:t为偶数时,当前项比其他项多1,所以我们把求出的系数减一后乘以每个数并求和,然后额外加一个当前项;t为奇数时,当前项比其他项少1,所以我们把求出的系数加一后乘以每个数并求和,然后额外减一个当前项。按格式输出后即可AC~
AC代码:
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
typedef long long LL;
const LL MOD = 98765431;
using namespace std;
LL KSM(LL a, LL n)
{
if (n==1)
return a%MOD;
LL ans = KSM(a,n>>1);
if (n&1)
ans = ans*ans%MOD*a%MOD;
else
ans = ans*ans%MOD;
return ans;
}
int main()
{
LL n,t;
LL ans = 0,a[50010]={0};
scanf("%I64d%I64d",&n,&t);
LL x = ((((1-n)%MOD*KSM(n,MOD-2)%MOD) * (KSM(-1,t+1)+KSM(n-1,t)%MOD))%MOD + KSM(n-1,t))%MOD;
if ((t&1)==0)
x = (x-1)%MOD;
else
x = (x+1)%MOD;
for (int i=0; i!=n; ++i)
{
scanf("%I64d",&a[i]);
a[i] %= MOD;
ans = (ans+a[i]*x%MOD)%MOD;
}
for (int i=0; i!=n; ++i)
if (t&1)
printf("%I64d\n",(ans-a[i])%MOD);
else
printf("%I64d\n",(ans+a[i])%MOD);
return 0;
}