Educational Codeforces Round 52 (Rated for Div. 2) E. Side Transmutations(数学)

题目链接:http://codeforces.com/contest/1065/problem/E

 

理论推理一下,发现每一块都是相互独立的,然后分块计数就行了

 

代码:

#include
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair pii;
const int MOD=998244353;
const int MAXN=2e5+5;
int b[MAXN];
ll qpow(ll a,ll b)
{
	ll ret=1;a%=MOD;
    for(ll i=b;i;i>>=1,a=a*a%MOD)
        if(i&1) ret=ret*a%MOD;
    return ret;
}
void mul(ll &a,ll b)
{
	a=(a*b)%MOD;
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n,m,A;
	scanf("%d%d%d",&n,&m,&A);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&b[i]);
	}
	ll ans=1;
	for(int i=1;i<=m;i++)
	{
		ll cnt=b[i]-b[i-1];
		mul(ans,((qpow(A,cnt)*(qpow(A,cnt)+1))%MOD*qpow(2,MOD-2)%MOD));
		n-=2*cnt;
	}
	mul(ans,qpow(A,n));
	printf("%lld\n",ans);
	return 0;
}

 

你可能感兴趣的:(codeforces)