QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639202 | #8050. Random Permutation | IllusionaryWhiteTraveler# | WA | 2661ms | 9976kb | C++20 | 1.6kb | 2024-10-13 18:16:15 | 2024-10-13 18:16:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 300000 + 5;
const int K = 300;
const int B = 1500;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7832kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 2661ms
memory: 9976kb
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:
13308677330602
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '13308677330602'