QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639199 | #8050. Random Permutation | IllusionaryWhiteTraveler# | WA | 1394ms | 8984kb | C++20 | 1.6kb | 2024-10-13 18:15:32 | 2024-10-13 18:15:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 300000 + 5;
const int K = 80;
const int B = 1000;
int N, a[MAX_N], pos[MAX_N];
ll solve(int mid, int lim) {
int l = max(1, mid - lim);
int r = min(N, mid + lim);
static int cntl[MAX_N << 1], cntr[MAX_N << 1];
int minv = N + 1, maxv = -N - 1;
for (int i = mid, j = 0; i >= l; i --) {
if (a[i] < a[mid]) j --;
else if (a[i] > a[mid]) j ++;
cntl[j + MAX_N] ++;
minv = min(minv, j);
maxv = max(maxv, j);
}
for (int i = mid, j = 0; i <= r; i ++) {
if (a[i] < a[mid]) j --;
else if (a[i] > a[mid]) j ++;
cntr[j + MAX_N] ++;
}
ll ans = 0;
for (int i = minv; i <= maxv; i ++) {
ans += 1ll * cntl[i + MAX_N] * (cntr[MAX_N - i] + cntr[MAX_N - i + 1]);
}
for (int i = mid, j = 0; i >= l; i --) {
if (a[i] < a[mid]) j --;
else if (a[i] > a[mid]) j ++;
cntl[j + MAX_N] = 0;
}
for (int i = mid, j = 0; i <= r; i ++) {
if (a[i] < a[mid]) j --;
else if (a[i] > a[mid]) j ++;
cntr[j + MAX_N] = 0;
}
return ans * a[mid];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i ++) {
cin >> a[i];
pos[a[i]] = i;
}
ll ans = 0;
for (int i = 1; i <= N; i ++) {
int x = abs(N / 2 - i) + 1;
int lim = N / i * K + B;
ans += solve(pos[i], lim);
}
cout << ans << '\n';
cerr << "time : " << clock() << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5736kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 1394ms
memory: 8984kb
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:
7709244940798
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '7709244940798'