QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202059 | #1831. Bruteforce | isaunoya | WA | 8ms | 48508kb | C++23 | 3.4kb | 2023-10-05 18:57:05 | 2023-10-05 18:57:05 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (int i = 0; i < a; i++)
#define rep2(i, a) for (int i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
int n, k, w, q;
const int N = 131072;
const int P = 998244353;
int cnt[N * 2], s[N * 2][6], s2[N * 2][6][6];
int c[6][6], pw[N][6];
int power(int x, int y) {
int res = 1;
while (y) {
if (y % 2 == 1) {
res = 1ll * res * x % P;
}
y /= 2;
x = 1ll * x * x % P;
}
return res;
}
int inverse(int x) { return power(x, P - 2); }
void md(int &x) {
if (x >= P) {
x -= P;
}
}
void pu(int x) {
int sz = cnt[x * 2];
cnt[x] = cnt[x * 2] + cnt[x * 2 + 1];
memcpy(s[x], s[x * 2], sizeof s[x]);
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= i; j++) {
md(s[x][i] += 1ll * s[x * 2 + 1][j] * c[i][j] % P * pw[sz][i - j] % P);
}
}
memcpy(s2[x], s2[x * 2], sizeof s2[x]);
for (int i = 0; i < w; i++) {
for (int j = 0; j < w; j++) {
s2[x][(i + sz) % w][j] += s2[x * 2 + 1][i][j];
}
}
}
void upd(int x, const int &v) {
int X = x + N;
int &c = cnt[X];
if (v == 1) {
c += 1;
for (int i = 0; i <= k; i++) {
md(s[X][i] += 1ll * pw[c][i] * x % P);
}
s2[X][c % w][x % w] += 1;
} else {
for (int i = 0; i <= k; i++) {
md(s[X][i] += P - 1ll * pw[c][i] * x % P);
}
s2[X][c % w][x % w] -= 1;
c -= 1;
}
while (X >>= 1) {
pu(X);
}
}
void solve() {
cin >> n >> k >> w;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
upd(a[i], 1);
}
cin >> q;
const int ivw = inverse(w);
while (q--) {
int x, y;
cin >> x >> y;
--x;
upd(a[x], -1);
upd(a[x] = y, 1);
int ans = s[1][k];
for (int i = 1; i < w; i++) {
for (int j = 1; j < w; j++) {
int c = s2[1][i][j];
md(ans += P - 1ll * c * pw[i][k] % P * j % P);
}
}
cout << 1ll * ans * ivw % P << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 0; i < N; i++) {
pw[i][0] = 1;
for (int j = 1; j < 6; j++) {
pw[i][j] = 1ll * pw[i][j - 1] * i % P;
}
}
for (int i = 0; i < 6; i++) {
c[i][0] = c[i][i] = 1;
for (int j = 1; j <= i; j++) {
c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
}
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: 0ms
memory: 18924kb
input:
3 1 1 2 2 8 2 2 5 3 6
output:
36 30
result:
ok 2 number(s): "36 30"
Test #2:
score: 0
Accepted
time: 3ms
memory: 18300kb
input:
4 2 2 1 3 3 7 4 1 1 2 4 3 8 4 8
output:
75 80 103 108
result:
ok 4 number(s): "75 80 103 108"
Test #3:
score: 0
Accepted
time: 3ms
memory: 42596kb
input:
10 1 1 16251 28898 58179 69362 48663 81443 34949 87167 16552 58931 10 6 89124 8 27159 4 7332 1 15852 9 67405 7 19413 10 97472 7 31114 6 31847 5 43794
output:
3511390 3107346 2780002 2779204 3079414 3018965 3365708 3406982 2970195 2936112
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 47328kb
input:
100 2 2 44625 87890 57662 73552 89172 64466 22834 24089 60132 5187 88984 19022 67559 53954 42114 19018 80035 3367 50518 15479 72359 15452 38886 5945 34974 86214 16805 71388 48981 45377 34170 61384 88881 29453 94738 94669 56746 80508 79155 94505 82745 38134 41769 2032 23186 5636 39727 54400 86133 497...
output:
81216962 152846115 156547587 163221145 293598979 178882623 92185541 202208317 181562234 200670345 213033267 262881364 247600647 301317991 271334928 261885869 261690216 247578015 236998290 291971331 293746018 424418987 402413699 300515771 300819876 344295103 391424353 392633865 361623113 355154190 47...
result:
ok 100 numbers
Test #5:
score: -100
Wrong Answer
time: 8ms
memory: 48508kb
input:
1000 5 5 67444 21858 17070 50937 22108 62205 2999 96284 84111 16255 69173 11611 84406 28349 95817 86160 87289 19642 22706 44359 31899 36187 15946 86429 23120 65928 81187 32204 37790 18497 52182 23455 59579 78480 45277 57706 60123 99315 19014 72404 35420 14632 12210 38628 1729 18606 23941 96652 80784...
output:
448878964 318528034 90265108 811499139 536371864 692453359 62887179 201189837 656170170 39198452 904799584 682227051 415333654 171933481 307331249 263624990 240288548 817201456 279077093 608920419 743946446 313011616 146240804 684506820 105563346 927435753 395334356 939970083 927940220 210760566 871...
result:
wrong answer 1st numbers differ - expected: '448982964', found: '448878964'