QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686583 | #9477. Topological Sort | real_sigma_team# | WA | 0ms | 3804kb | C++23 | 874b | 2024-10-29 14:30:50 | 2024-10-29 14:30:50 |
Judging History
answer
#include <bits/stdc++.h>
const int mod = 998244353;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
return a >= b ? a - b : a + mod - b;
}
int mul(int a, int b) {
return 1ll * a * b % mod;
}
int power(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
return res;
}
int inv(int x) {
return x == 1 ? 1 : sub(0, mul(mod / x, inv(mod % x)));
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n;
std::cin >> n;
std::vector<int> fenw(n);
int ans = 1;
for (int i = 0; i < n; ++i) {
int x;
std::cin >> x;
x--;
int sm = 0;
for (int i = x; i >= 0; i &= i + 1, i--) sm += fenw[i];
for (int i = x; i < n; i |= i + 1) fenw[i]++;
sm = std::max(sm, i - 1);
ans = mul(ans, power(2, sm));
}
std::cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
3 1 3 2
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
5 1 2 3 4 5
output:
1024
result:
ok "1024"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
6 4 2 1 5 6 3
output:
4096
result:
ok "4096"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3548kb
input:
492 397 486 227 395 58 452 172 216 130 181 268 482 85 209 365 104 373 90 260 326 252 96 267 106 102 398 441 41 292 314 12 78 242 353 153 424 179 86 299 228 54 390 73 465 396 349 4 10 451 99 342 250 391 6 323 197 159 47 136 473 392 77 125 362 418 255 291 13 238 339 8 28 413 121 384 157 152 23 221 305...
output:
390557336
result:
wrong answer 1st words differ - expected: '73428942', found: '390557336'