QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469282 | #8050. Random Permutation | zlt | WA | 914ms | 6416kb | C++14 | 1.1kb | 2024-07-09 17:02:33 | 2024-07-09 17:02:33 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 300100;
int n, a[maxn], b[maxn], c[maxn << 1];
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
b[a[i]] = i;
}
ll ans = 0;
for (int i = 1; i <= n; ++i) {
db x = fabs(i - 1. * (n + 1) / 2) / n;
int lim = max((ll)(15 / (x * x)), 100LL);
for (int j = b[i] - 1, s = 0; j >= max(0, b[i] - lim); --j) {
++c[s + n];
s += (a[j] <= i ? 1 : -1);
}
ll res = 0;
for (int j = b[i], s = 0; j <= min(n, b[i] + lim); ++j) {
s += (a[j] <= i ? 1 : -1);
res += c[-s + n] + c[-s + n + 1];
}
ans += res * i;
for (int j = b[i] - 1, s = 0; j >= max(0, b[i] - lim); --j) {
--c[s + n];
s += (a[j] <= i ? 1 : -1);
}
}
printf("%lld\n", ans);
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6000kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 914ms
memory: 6416kb
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:
243975952452370
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '243975952452370'