期望得分:100+100+100=300

实际得分:72+12+0=84

 

 T1  [CQOI2009]中位数图

令c[i]表示前i个数中,比d大的数与比d小的数的差,那么如果c[l]=c[r],则[l+1,r]满足条件

#include<cstdio>
#include<iostream>
using namespace std;
const int N=1e7;
int c[N*2],g[N];
void read(int &x)
{
    x=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-'0'; c=getchar();}
}
int main()
{
    
    int n,d,x,now=0,pos;
    long long ans=0;
    bool ok=false;
    read(n); read(d);
    c[n]=1;
    for(int i=1;i<=n;i++)
    {
        read(x);
        if(x<d) now--;
        else if(x>d) now++;
        if(x==d) ok=true,pos=i; 
        if(!ok) c[now+n]++;
        else g[i]=now;
    }
    for(int i=pos;i<=n;i++) ans+=c[g[i]+n];
    printf("%lld",ans);
}
View Code

相关文章:

  • 2021-06-17
  • 2021-11-06
  • 2021-08-11
  • 2021-06-05
  • 2021-08-15
  • 2021-11-13
  • 2021-05-27
  • 2021-09-25
猜你喜欢
  • 2021-10-24
  • 2021-08-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-07-23
  • 2021-12-26
相关资源
相似解决方案