QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#373994 | #8050. Random Permutation | JerryTcl | WA | 1819ms | 4584kb | C++20 | 907b | 2024-04-02 10:49:54 | 2024-04-02 10:49:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n; vector<int> a(n + 1), p(n + 1);
for(int i = 1; i <= n; ++i) cin >> a[i], p[a[i]] = i;
long long ans = 0; vector<int> buf(2 * n + 3);
int *const c = buf.data() + n + 1;
for(int i = 1; i <= n; ++i) {
const double t = abs(0.5 - 1.0 * (i - 1) / (n - 1));
const int lim = max<int>(20 / max(t * t, 1e-6), 100);
const int w = p[i], L = max(1, w - lim), R = min(n, w + lim);
long long tmp = 0; int l = 0, r = 0;
for(int q = w, y = 0; q >= L; --q)
++c[y += a[q] >= i ? 1 : -1];
for(int q = w, y = 0; q <= R; ++q)
y += a[q] >= i ? 1 : -1, tmp += c[-y] + c[-y + 1];
while(c[l - 1]) --l; while(c[r]) ++r;
fill(c + l, c + r, 0), ans += tmp * i;
}
printf("%lld\n", ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3728kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 1819ms
memory: 4584kb
input:
100000 56449 21738 74917 44834 36187 96576 37204 28451 3444 13029 66039 8955 51445 30706 27229 37159 66052 16691 70389 29935 44984 3648 75082 73600 76621 28345 5298 37940 49412 85260 92029 18185 84398 10233 79227 98312 96649 30680 65206 38879 75397 26951 11294 58085 37297 97167 59252 44104 4058 3796...
output:
250918151089066
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '250918151089066'