QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#353324 | #8050. Random Permutation | ucup-team134 | WA | 1346ms | 8424kb | C++17 | 861b | 2024-03-14 02:35:17 | 2024-03-14 02:35:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=300050;
const int S=50;
const int C=200;
int p[N],tmp[N],pos[N];
int bal[N],cnt[2*N];
int main(){
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++){
scanf("%i",&p[i]);
pos[p[i]]=i;
}
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<S;j++){
if(i+j-1<=n){
for(int z=0;z<j;z++){
tmp[z]=p[i+z];
}
nth_element(tmp,tmp+(j-1)/2,tmp+j);
ans+=tmp[(j-1)/2];
}
}
}
for(int mid=n/2-C;mid<=n/2+C;mid++){
if(mid>=1 && mid<=n){
for(int i=1;i<=n;i++){
bal[i]=bal[i-1]+(p[i]>mid)-(p[i]<mid);
if(i-S>=0 && i-S<pos[mid])cnt[N+bal[i-S]]++;
if(i>=pos[mid]){
ans+=(ll)(cnt[N+bal[i]]+cnt[N+bal[i]-1])*mid;
}
}
for(int i=0;i<=n;i++)cnt[N+bal[i]]=0;
}
}
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: 7984kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 1346ms
memory: 8424kb
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:
142820637670448
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '142820637670448'