UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213939#2380. 中位数a_sad_soulCompile Error//C++990b2024-11-14 19:28:412024-11-14 23:03:13

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+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];
ll b[MAXN];
const int  HF=5e5;
bool solve(ll mid){
    ll re=0;
    memset(tree,0,sizeof(tree));
    for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(a[i]>=mid?1:-1);
    add(HF,1);
    for(int i=1;i<=n;++i){
        re+=query(pre[i]+HF);
        add(pre[i]+HF,1);
    }
    if(re*2>=1ll*n*(n+1)/2)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,[](auto x,auto y){return x<y;});
    int l=1,r=n;ll 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;
}

详细

answer.code: In function 'int main()':
answer.code:31:28: error: 'x' does not name a type
     sort(x+1,x+1+n,[](auto x,auto y){return x<y;});\x0d
                            ^
answer.code:31:49: error: ISO C++ forbids declaration of 'parameter' with no type [-fpermissive]
     sort(x+1,x+1+n,[](auto x,auto y){return x<y;});\x0d
                                                 ^
answer.code: In lambda function:
answer.code:31:51: error: expected '{' before ';' token
     sort(x+1,x+1+n,[](auto x,auto ...