QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469146 | #8050. Random Permutation | wsyear | WA | 1651ms | 10124kb | C++14 | 1.7kb | 2024-07-09 14:56:51 | 2024-07-09 14:56:51 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
using namespace std;
const int maxn = 2000010;
const int base = 2000000;
mt19937 rnd(114514);
int n, a[maxn], cntl[maxn << 1], cntr[maxn << 1];
int main() {
// freopen("median.in", "r", stdin);
// freopen("median.out", "w", stdout);
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n;
rep (i, 1, n) cin >> a[i];
// rep (i, 1, n) a[i] = i;
// shuffle(a + 1, a + n + 1, rnd);
ll ans = 0;
rep (i, 1, n) {
int lim = 2e5 / pow(max(1, abs(a[i] - n / 2)), .75);
int s0 = 0, s1 = 0, mxf = 0, mxg = 0, mnf = 0, mng = 0, l = i, r = i;
ll s = 1;
cntl[base]++, cntr[base]++;
while (true) {
if (abs(s0 + s1) > lim || (l == 1 && r == n)) break;
if (l > 1) {
--l, s0 += (a[l] < a[i] ? -1 : 1);
s += cntr[base - s0] + cntr[base - s0 + 1];
cntl[s0 + base]++;
chkmn(mnf, s0), chkmx(mxf, s0);
}
if (r < n) {
++r, s1 += (a[r] < a[i] ? -1 : 1);
s += cntl[base - s1] + cntl[base - s1 + 1];
cntr[s1 + base]++;
chkmn(mng, s1), chkmx(mxg, s1);
}
}
rep (i, mnf, mxf) cntl[i + base] = 0;
rep (i, mng, mxg) cntr[i + base] = 0;
ans += s * a[i];
}
cout << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 10124kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: 0
Accepted
time: 818ms
memory: 10096kb
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:
250202478701074
result:
ok 1 number(s): "250202478701074"
Test #3:
score: -100
Wrong Answer
time: 1651ms
memory: 10092kb
input:
200000 70900 189146 39056 135530 191967 133789 108558 81993 132081 113826 54456 127761 27836 64897 87159 105191 109446 81230 75525 90396 75756 50200 43091 151358 100791 193998 157161 119352 176873 120724 134471 155040 138534 182263 161855 4577 124893 199710 60764 146460 75314 43696 129155 64816 1390...
output:
1998639552389349
result:
wrong answer 1st numbers differ - expected: '1998651699409551', found: '1998639552389349'