QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671487 | #8050. Random Permutation | ucup-team4992 | WA | 1229ms | 7832kb | C++14 | 1.9kb | 2024-10-24 12:51:06 | 2024-10-24 12:51:07 |
Judging History
answer
#include <bits/stdc++.h>
#pragma optimize(2)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
static const int K = 10;
static const int maxn = 3e5 + 10;
static const int ZERO = 3e5 + 1;
int cntr[2][maxn << 1];
void solve() {
// freopen("data.txt", "r", stdin);
double prev = clock();
ll ans = 0;
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
int tl = 0;
for (int i = 1; i <= n; i++) {
int lsum = 0, rsum = 0;
int l = i, r = i;
ll res = 0;
cntr[i & 1][ZERO]++;
int k = max(1, abs(n / 2 - a[i]));
int len = K * ll(n) * n / (ll(k) * k);
tl += len;
int L = max(1, i - len), R = min(n, i + len);
while (l > L) {
l--;
lsum += (a[l] > a[i] ? 1 : -1);
}
while (r < R) {
r++;
rsum += (a[r] > a[i] ? 1 : -1);
cntr[r & 1][ZERO + rsum]++;
}
// cout << L << ' ' << R << ' ' << lsum << ' ' << rsum << '\n';
while (l <= i) {
res += cntr[l & 1][ZERO - lsum];
res += cntr[(l & 1) ^ 1][ZERO - lsum + 1];
lsum -= (a[l] > a[i] ? 1 : -1);
l++;
}
while (r >= i) {
cntr[r & 1][ZERO + rsum]--;
rsum -= (a[r] > a[i] ? 1 : -1);
r--;
}
// cout << res << '\n';
ans += res * a[i];
}
cout << ans << '\n';
double cur = clock();
// cout << "Time=" << (cur - prev) / CLOCKS_PER_SEC << '\n';
// cout << "tot len=" << tl << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--)
solve();
return 0;
}
/*
4
1 4 2 3
250202478701074
246631252049141
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 1229ms
memory: 7832kb
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:
246866814874206
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '246866814874206'