QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671485 | #8050. Random Permutation | ucup-team4992 | WA | 396ms | 7700kb | C++14 | 1.8kb | 2024-10-24 12:49:53 | 2024-10-24 12:49:53 |
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 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 = 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
77987580201049
36490923129641
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7700kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 396ms
memory: 5756kb
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:
248080984079685
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '248080984079685'