[Cnoi 2021]

[Cnoi2021]矩阵

// ExtraTime Common Header Simple over C++14
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define rint(x) int x;cin>>x;
#define rll(x) ll x;cin>>x;
#define rs(x) string x;cin>>x;
#define rvi(v,n) vector<int>v(n);for(auto &i:v)cin>>i;
#define rvl(v,n) vector<ll>v(n);for(auto &i:v)cin>>i;
inline int fpow(int a,int b,int p){//a^b mod p; assert(p!=0);
	int ans=1%p,base=a%p;
	for(;b;b/=2){
		if(b&1)ans=(ll)ans*base%p;
		base=(ll)base*base%p;
	}
	return ans;
}
constexpr int mod = (119 << 23) + 1; // 998244353
int main(){
	ios::sync_with_stdio(0),cin.tie(0);cin.exceptions(ios::badbit | ios::failbit);
	rll(n)rll(k)
	if(k==0){
		cout<<n%mod<<'\n';
		return 0;
	}
	else {
		rvl(v1,n);
		rvl(v2,n);
		ll sum1=0,sum2=0;
		for(auto i:v1)(sum1+=i)%=mod;
		for(auto i:v2)(sum2+=i)%=mod;
		ll sum=sum1*sum2%mod;
		if(k==1){
			cout<<(sum+mod)%mod<<'\n';
		}
		else{
			ll p=0;
			for(int i=0;i<n;++i)
			(p+=v1[i]*v2[i]%mod+mod)%=mod;
			cout<<(fpow(p,k-1,mod)*sum%mod+mod)%mod<<'\n';
		}
	}
	return 0;
}
上一篇:# Java学习笔记(三) ——基础知识篇


下一篇:C语言预处理器和输入\输出函数