ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213927 | #2380. 中位数 | a_sad_soul | 0 | 1126ms | 14132kb | C++ | 989b | 2024-11-14 19:11:47 | 2024-11-14 23:02:12 |
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 6e5+10;
typedef long long ll;
int lowbit(int i){return i&(-i);}
int n;
ll tree[MAXN];
void add(int i,ll v){
for(;i<MAXN;i+=lowbit(i))tree[i]+=v;
}
ll query(int i){ll re=0;for(;i;i-=lowbit(i))re+=tree[i];return re;}
ll a[MAXN],pre[MAXN];
int b[MAXN];
int HF=MAXN/2;
bool solve(ll mid){
ll re=0;memset(tree,0,sizeof(tree));
for(int i=1;i<=n;++i){
if(a[i]>=mid)b[i]=1;
else b[i]=-1;
pre[i]=pre[i-1]+b[i];
}add(HF,1);
for(int i=1;i<=n;++i){
re+=query(pre[i]+HF);add(pre[i]+HF,1);
}if(re*re>=(n*(n+1)/2+1))return true;
return false;
}
ll x[MAXN];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lld",&a[i]),x[i]=a[i];
sort(x+1,x+1+n);int l=0,r=n,ans;
while(l<=r){
int mid=(l+r)>>1;
if(solve(x[mid]))ans=x[mid],l=mid+1;
else r=mid-1;
}
cout<<ans<<endl;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 5940kb
input:
200 247837946 222748444 549404903 934970141 181690491 116150147 755881953 912914845 578004877 589768...
output:
827973880
result:
wrong answer 1st numbers differ - expected: '411892743', found: '827973880'
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 5936kb
input:
200 504553675 321343511 781936447 172776833 779139954 643752948 106 164 303976944 828799931 11502170...
output:
849868036
result:
wrong answer 1st numbers differ - expected: '451369372', found: '849868036'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 5936kb
input:
200 738368650 91602659 340556191 835209882 409442204 656938221 258295858 90658347 126689369 56196859...
output:
835209882
result:
wrong answer 1st numbers differ - expected: '420852999', found: '835209882'
Test #4:
score: 0
Wrong Answer
time: 4ms
memory: 6060kb
input:
5000 300051244 685920750 122806687 315801142 33592358 339985437 262520930 380010194 687330910 550362...
output:
883053460
result:
wrong answer 1st numbers differ - expected: '465193387', found: '883053460'
Test #5:
score: 0
Wrong Answer
time: 8ms
memory: 6064kb
input:
5000 108135249 950186870 146626753 682580494 744412491 4159 995071655 157947560 668940645 878891308 ...
output:
862287300
result:
wrong answer 1st numbers differ - expected: '466892796', found: '862287300'
Test #6:
score: 0
Wrong Answer
time: 9ms
memory: 6060kb
input:
5000 246610103 780664789 678774940 716124165 518453378 300121008 135383319 939869983 430946660 13412...
output:
873915404
result:
wrong answer 1st numbers differ - expected: '470507384', found: '873915404'
Test #7:
score: 0
Wrong Answer
time: 222ms
memory: 14132kb
input:
300000 786856547 380253059 684225515 795392038 881780483 18437791 793783577 832330260 801624996 3466...
output:
-177021040
result:
wrong answer 1st numbers differ - expected: '463539280', found: '-177021040'
Test #8:
score: 0
Wrong Answer
time: 251ms
memory: 14128kb
input:
300000 951000485 930070933 3566360 157114366 150196488 611226665 123590886 950624066 472150346 57976...
output:
285722882
result:
wrong answer 1st numbers differ - expected: '462334620', found: '285722882'
Test #9:
score: 0
Wrong Answer
time: 274ms
memory: 14132kb
input:
300000 728509094 406128756 696166390 756254976 31403187 672131182 35544213 870708756 3659210 5227553...
output:
999998820
result:
wrong answer 1st numbers differ - expected: '464162969', found: '999998820'
Test #10:
score: 0
Wrong Answer
time: 350ms
memory: 14128kb
input:
300000 804874490 52247250 546638789 400214210 383796618 47995083 814777769 507157584 466189162 28296...
output:
999993004
result:
wrong answer 1st numbers differ - expected: '463577194', found: '999993004'