QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#334065 | #8050. Random Permutation | hos_lyric | WA | 937ms | 4468kb | C++14 | 2.7kb | 2024-02-21 05:39:42 | 2024-02-21 05:39:42 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
const double L = 200;
int N;
vector<int> P;
int main() {
for (; ~scanf("%d", &N); ) {
P.assign(N + 2, 0);
for (int i = 1; i <= N; ++i) {
scanf("%d", &P[i]);
}
Int ans = 0;
Int sumM=0;
vector<int> freq(2 * N + 3, 0);
for (int i = 1; i <= N; ++i) {
/*
interval of length m + 1
binomial distribution
Pr[small] = p
E[# small] = m p
V[# small] = m p (1 - p)
E[large - small] = m (1 - 2 p)
V[large - small] = 4 m p (1 - p)
let 0 or +1 lie within m (1 - 2 p) +- L * 2 sqrt(m p (1 - p))
*/
const int a = P[i];
const double p = (a - 1) / (double)(N - 1);
int m = L * 2 * sqrt(p * (1 - p)) / max(abs(1 - 2 * p), 1e-6);
m = min(max(m, 100), N);
sumM+=m;
fill(freq.begin(), freq.begin() + (2 * m + 3), 0);
int now = m + 1;
++freq[now];
for (int j = i - 1; j >= 1 && j >= i - m; --j) {
(P[j] < a) ? --now : ++now;
++freq[now];
}
Int here = 0;
now = m + 1;
here += freq[2 * m + 2 - now] + freq[2 * m + 3 - now];
for (int j = i + 1; j <= N && j <= i + m; ++j) {
(P[j] < a) ? --now : ++now;
here += freq[2 * m + 2 - now] + freq[2 * m + 3 - now];
}
// cerr<<a<<": "<<m<<" "<<here<<endl;
ans += here * a;
}
cerr<<"sumM = "<<sumM<<endl;
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 937ms
memory: 4468kb
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:
241311045936559
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '241311045936559'