Untitled
unknown
plain_text
a year ago
2.9 kB
12
Indexable
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <random> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define AboTaha_on_da_code ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define X first #define Y second const int dx[8]={0, 0, 1, -1, 1, -1, -1, 1}; const int dy[8]={1, -1, 0, 0, 1, -1, 1, -1}; const double EPS = 1e-8; const int mod = 1e9+7; // 1e9+7, 998244353 const int phi = 1e9+6; // 1e9+6, 998244352 // BEFORE coding are you sure you understood the statement correctly? // PLEASE do not forget to read the sample explanation carefully. // WATCH out for overflows & RTs in general. // TEST your idea or code on the corner cases. // ANALYZE each idea you have thoroughly. struct Matrix { vector <vector <int>> mat; int mod; Matrix(int sz, int init, int m) { mod = m; mat.resize(sz, vector <int> (sz, init)); } Matrix operator * (Matrix &oth) { int sz = mat.size(); Matrix res(sz, 0, mod); for (int i = 0; i < sz; i++) { for (int j = 0; j < sz; j++) { for (int k = 0; k < sz; k++) { res.mat[i][j] += 1LL*mat[i][k]*oth.mat[k][j]%mod; res.mat[i][j]%=mod; } } } return res; } void operator *= (Matrix &oth) { *this = *this*oth; } }; Matrix mpow(Matrix a, ll b) { Matrix res((int)a.mat.size(), 0, mod); for (int i = 0; i < a.mat.size(); i++) res.mat[i][i] = 1; while(b) { if (b&1) res*=a; a*=a, b/=2; } return res; } void burn(int tc) { int n, k; cin >> n >> k; vector <int> a(n); for (auto &i : a) cin >> i; Matrix tr1(n, 0, mod); for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { tr1.mat[i][j] = j+1; } } Matrix tr2(n, 0, mod); for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { tr2.mat[i][j] = i-j+1; } } Matrix tr = tr2*tr1; tr = mpow(tr, k/2); if (k&1) tr = tr1*tr; for (int i = 0; i < n; i++) { int cur = 0; for (int j = 0; j <= i; j++) { cur+=1LL*tr.mat[i][j]*a[j]%mod; if (cur >= mod) cur-=mod; } cout << cur << ' '; } } int main() { AboTaha_on_da_code // freopen("cheat.in", "r", stdin); // freopen("output.txt", "w", stdout); int T = 1; // cin >> T; for (int i = 1; i <= T; i++) { // cout << "Case " << i << ": "; burn(i); cout << '\n'; } return (0-0); }
Editor is loading...
Leave a Comment