Link:

传送门

A:

按值大小插入后用树状数组统计两边个数

#include <bits/stdc++.h>

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e5+10;
P dat[MAXN];
int n,bit[MAXN],dsp[MAXN],l[MAXN],r[MAXN],res,tot;

void Update(int x)
{while(x<=n) bit[x]++,x+=x&(-x);}
int Query(int x)
{
    int ret=0;
    while(x) ret+=bit[x],x-=x&(-x);
    return ret;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) 
        scanf("%d",&dat[i].X),dsp[++tot]=dat[i].X,dat[i].Y=i;
    sort(dsp+1,dsp+n+1);tot=unique(dsp+1,dsp+n+1)-dsp-1;
    for(int i=1;i<=n;i++)
        dat[i].X=lower_bound(dsp+1,dsp+tot+1,dat[i].X)-dsp;
    sort(dat+1,dat+n+1,greater<P>());
    
    for(int i=1;i<=n;i++)
    {
        l[i]=Query(dat[i].Y-1);
        r[i]=i-1-l[i];Update(dat[i].Y);
        if(max(l[i],r[i])>min(l[i],r[i])*2) res++;
    }
    printf("%d",res);
    return 0;
}
Problem A

相关文章:

  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2022-01-16
  • 2021-07-20
  • 2021-10-26
猜你喜欢
  • 2021-12-01
  • 2021-10-06
  • 2021-10-13
  • 2021-09-25
  • 2021-10-18
  • 2021-09-26
  • 2021-06-24
相关资源
相似解决方案