QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252952 | #5547. Short Function | warner1129# | WA | 1ms | 3496kb | C++20 | 3.1kb | 2023-11-16 15:44:24 | 2023-11-16 15:44:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<i128, i128>;
template<class T>
inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;
Pt operator+(Pt a, Pt b) { return {a.ff + b.ff, a.ss + b.ss}; }
Pt operator-(Pt a, Pt b) { return {a.ff - b.ff, a.ss - b.ss}; }
i128 operator^(Pt a, Pt b) { return a.ff * b.ss - a.ss * b.ff; }
i128 cro(Pt a, Pt b, Pt c) { return (b - a) ^ (c - a); }
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
int power(int a, int b) {
int r = 1;
for (; b; b >>= 1, a = mul(a, a))
if (b & 1) r = mul(r, a);
return r;
}
void solve() {
int n, K;
cin >> n >> K;
vector<int> A(n * 2);
int m = 1;
for (int i = 0; i < n; i++) {
cin >> A[i];
A[i + n] = A[i];
m = mul(m, A[i]);
}
auto cal = [&](int p) -> pair<int, int> {
// x = {q * N, r}
auto Mul = [&](pair<i64, i64> a, pair<i64, i64> b) -> pair<i64, i64> {
i64 q, r;
q = (a.ff * b.ff * n + a.ff * b.ss + a.ss * b.ff) % (mod - 1);
r = (a.ss * b.ss);
(q += r / n) %= (mod - 1);
r %= n;
return {q, r};
};
pair<i64, i64> a{2 / n, 2 % n}, R{1 / n, 1 % n};
for (; p; p >>= 1, a = Mul(a, a))
if (p & 1) R = Mul(R, a);
return R;
};
auto [h, len] = cal(K);
debug(h, len);
m = power(m, h);
const int lgN = __lg(n * 2);
vector st(lgN + 1, vector<int>(n * 2));
for (int i = 0; i < n * 2; i++) st[0][i] = A[i];
for (int i = 0; (2 << i) <= n * 2; i++) {
for (int j = 0; j + (2 << i) <= n * 2; j++) {
st[i + 1][j] = mul(st[i][j], st[i][j + (1 << i)]);
}
}
auto ask = [&](int l, int r) -> int {
int s = 1;
int p = l;
for (int i = lgN; i >= 0; i--) {
if (p + (1 << i) <= r) {
s = mul(s, st[i][p]);
p += (1 << i);
}
}
return s;
};
for (int i = 0; i < n; i++) {
cout << mul(m, ask(i, i + len)) << " \n"[i == n - 1];
}
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3408kb
input:
5 2 1 2 3 4 5
output:
24 120 60 40 30
result:
ok 5 number(s): "24 120 60 40 30"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3368kb
input:
8 3 12 5 16 14 10 6 9 2
output:
14515200 14515200 14515200 14515200 14515200 14515200 14515200 14515200
result:
ok 8 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
6 10 3 7 8 2 9 5
output:
56347321 169041963 833775940 811788154 844769833 639990479
result:
ok 6 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3400kb
input:
2 100 1 2
output:
917380677 917380677
result:
ok 2 number(s): "917380677 917380677"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3412kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3444kb
input:
119 1000000000 179906895 883175111 831258723 617910763 41850684 952649819 667608052 992898634 871657688 261948841 858714230 452797779 698675390 39373823 268148685 762575950 789163136 676908074 134428624 583625412 549545785 415007638 564283552 596519552 575204092 884934270 632550339 21505752 66058955...
output:
472528588 421083764 424046257 521115109 691312906 975139031 549567013 559740297 887671724 43215552 31680581 835907186 455472309 931759712 503958056 509876164 37426721 482782101 314508367 922850625 495198204 325486146 848353580 973544226 907351474 516623637 976899450 510192346 924884083 355936939 906...
result:
wrong answer 1st numbers differ - expected: '375116230', found: '472528588'