Untitled
unknown
c_cpp
a year ago
2.5 kB
8
Indexable
#include <bits/stdc++.h>
#define ll long long
#define stp(n) fixed<<setprecision(n)
#define flash cin.tie(0); cin.sync_with_stdio(0);
#define el '\n'
# define pll pair<ll,ll>
# define pi pair<int,int>
#define popCnt(x) (__builtin_popcountll(x))
#define LSB(x) (__builtin_ffsll(x) - 1)
#define MSB(x) (64 - __builtin_clzll(x) - 1).
using namespace std;
//#pragma GCC optimize("03")
//#pragma GCC target("tune=native")
//#pragma GCC optimize("unroll-loops")
const ll mod = 998244353;
//ll mul(const ll &a, const ll &b) {
// return (a % mod + mod) * (b % mod + mod) % mod;
//}
//
//ll add(const ll &a, const ll &b) {
// return (a + b + 2 * mod) % mod;
//}
const int N = 1e2, inf = 2e9;
const ll infl = 2e18;
typedef vector<long long> row;
typedef vector<row> matrix;
#define sz(x) (int)x.size()
matrix zero(int n, int m) {
return matrix(n, row(m, 0));
}
matrix iden(int n) {
matrix ret = zero(n, n);
for (int i = 0; i < n; i++) ret[i][i] = 1;
return ret;
}
matrix mul(const matrix &a, const matrix &b) {
matrix ret = zero(sz(a), sz(b[0]));
for (int i = 0; i < sz(a); ++i) {
for (int j = 0; j < sz(b[0]); ++j) {
for (int k = 0; k < sz(a[0]); ++k) {
ret[i][j] += a[i][k] * b[k][j] % mod;
ret[i][j] %= mod;
}
}
}
return ret;
}
matrix pow(const matrix &a, ll k) {
if (k == 0) return iden(sz(a));
if (k % 2) return mul(a, pow(a, k - 1));
return pow(mul(a, a), k / 2);
}
void testCase() {
//5 0 1 0 7 6 2
// 4 3 7 4 6 8
ll n, k;
cin >> n >> k;
ll a[n], sum = 0;
for (ll &i: a) {
cin >> i;
sum += i;
sum%=mod;
}
if (k == 0) {
for (int i = 0; i < n; ++i) cout << a[i] << el;
return;
}
for (int i = 0; i < n; ++i) {
matrix init = {{a[i], sum},
{0, 0}}, transition = {{-2, 0},
{1, n - 2}}, overallMalt;
matrix x = pow(transition, k);
overallMalt = mul(init, x);
cout << overallMalt[0][0] << el;
}
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
flash;
int T = 1;
// cin >> T;
while (T--) {
// cout<<"slkfjd";
testCase();
// cout << el;
// cout << endl;
}
}Editor is loading...
Leave a Comment