QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#340878 | #984. Happiness | ucup-team1209# | WA | 1ms | 3688kb | C++20 | 3.2kb | 2024-02-29 13:44:21 | 2024-02-29 13:45:42 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using db = double;
using ll = long long;
using u64 = unsigned long long;
const int mod = 998244353;
const int N = 1 << 19;
int pow(int a, int b, int ans = 1) {
for(;b;b >>= 1, a = (u64) a * a % mod) if(b & 1) {
ans = (u64) ans * a % mod;
}
return ans;
}
int wn[N], rev[N];
int lim, invlim;
void init(int len) {
lim = 2 << std::__lg(len - 1);
invlim = mod - (mod - 1) / lim;
for(static int i = 1;i < lim;i += i) {
wn[i] = 1;
const int w = pow(3, mod / i / 2);
for(int j = 1;j < i;++j) {
wn[i + j] = (u64) wn[i + j - 1] * w % mod;
}
}
for(int i = 1;i < lim;++i) {
rev[i] = rev[i >> 1] >> 1 | (i % 2u * lim / 2);
}
}
void DFT(int * a) {
static u64 t[N];
for(int i = 0;i < lim;++i) t[i]= a[rev[i]];
for(int i = 1;i < lim;i += i) {
for(int j = 0;j < lim;j += i + i) {
for(int k = 0;k < i;++k) {
const u64 x = t[i + j + k] * wn[i + k] % mod;
t[i + j + k] = t[k + j] + mod - x, t[k + j] += x;
}
}
}
for(int i = 0;i < lim;++i) a[i]= t[i] % mod;
}
void IDFT(int * a ){
DFT(a), std::reverse( a + 1, a + lim);
for(int i = 0;i < lim;++i) a[i] = (u64) a[i] * invlim % mod;
}
int n, q;
int v[N], vv[N];
int x[N], b[N];
int preb[N];
int prev[N];
int S;
void sub(int & x, int y) {
x -= y, x += x >> 31 & mod;
}
void add(int & x, int y) {
x += y;
if(x >= mod) x -= mod;
}
void build() {
memset(b, 0, lim << 2);
for(int i = 0;i < n;++i) {
int need = n / 2u - 1 + x[i];
b[(n * 4u - need) % n] += 1;
}
DFT(b);
for(int i = 0;i < lim;++i) {
b[i] = (u64) b[i] * vv[i] % mod;
}
IDFT(b);
for(int i = n;i < n + n;++i) {
add(b[i - n], b[i]);
b[i] = 0;
}
for(int i = n;i < n + n;++i) {
b[i] = b[i - n];
}
for(int i = 0;i < n + n;++i) {
preb[i] = b[i];
}
for(int i = n + n - 1;i >= 0;--i) {
add(preb[i], preb[i + 1]);
}
}
int main() {
#ifdef zqj
freopen("$.in", "r", stdin);
#endif
std::ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> q;
if(n % 2) {
for(int i = 0;i <= q;++i) {
puts("0");
}
return 0;
}
int nn = n / 2;
for(int i = 0;i < n;++i) {
cin >> v[i];
vv[i] = v[i];
}
for(int i = 0;i < n;++i) {
x[i] = i;
}
for(int i = 0;i < n * 2;++i) prev[i] = v[i % n];
for(int i = n * 2 - 1;i >= 0;--i) add(prev[i], prev[i + 1]);
init(n + n);
DFT(vv);
build();
std::vector<int> ins, del;
auto calc = [&]() {
int move = (n - S) % n;
int ans = preb[move] - preb[move + nn];
ans = (ans + mod) % mod;
for(int x : ins) {
int p = nn - 1 - S + x;
if(p < 0) p += n;
if(p >= n) p -= n;
add(ans, prev[p]);
sub(ans, prev[p + nn]);
}
for(int x : del) {
int p = nn - 1 - S + x;
if(p < 0) p += n;
if(p >= n) p -= n;
sub(ans, prev[p]);
add(ans, prev[p + nn]);
}
return ans;
};
cout << calc() << '\n';
const int B = 1000;
for(int i = 0;i < q;++i) {
int op, q, k;
cin >> op;
if(op == 1) {
cin >> k;
S = (S - k + n) % n;
} else {
cin >> q >> k;
q = (q + S) % n;
del.push_back(x[q]);
x[q] = (x[q] - k + n) % n;
ins.push_back(x[q]);
}
if(del.size() >= B) {
build();
del = ins = {};
}
cout << calc() << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
6 3 1 2 4 8 16 32 2 1 4 1 5 2 4 2
output:
189 168 210 252
result:
ok 4 number(s): "189 168 210 252"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
291 297 690864 66051 879316 361679 613199 616 951868 674311 509731 765530 914257 643036 149469 265479 385645 752029 360309 48606 545052 618893 70334 418974 673141 754792 299130 398298 719505 772883 898465 697947 205006 95537 798625 696927 962164 140276 704224 146457 73196 100864 371302 485115 950286...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 298 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
295 295 552765 106849 337718 329913 575893 164618 897059 355495 919669 763217 652119 598602 375615 550063 362338 802065 404469 248822 475588 743741 236314 886569 896687 949368 736118 824720 290749 488403 70211 243198 671570 94895 649763 349076 476023 628472 417057 350655 342355 826342 147267 922532 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 296 numbers
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3688kb
input:
296 292 197804 718425 56634 403100 978753 617316 121593 944167 884895 801844 613148 623615 822920 116431 372795 179915 790109 774901 961724 265875 718476 818274 593528 45207 199271 233902 751601 242247 11775 88033 912182 946726 998679 382162 791540 990712 283984 188914 36965 121390 716244 896446 236...
output:
860140359 860140359 860140359 860140359 860140359 863921724 857054622 866494711 854882721 864897919 860033075 856625675 850299904 863422443 868002634 851694090 848760765 872540825 868838833 867660684 866786569 868089053 852191665 855866185 851388533 851719274 849752638 862793137 859669489 849306719 ...
result:
wrong answer 1st numbers differ - expected: '712685820', found: '860140359'