[CQOI2009]中位数图
[CQOI2009]中位数图
https://ac.nowcoder.com/acm/problem/19913
#include<bits/stdc++.h> #define js ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; typedef long long ll; const int maxn = 100010; int qian[maxn<<1],sum,a,n,k,pos; int main() { js; cin>>n>>k; qian[n]=1; ll ans=0; for(ll i=1;i<=n;++i) { cin>>a; if(a==k) pos=i; if(a>=k) ++sum; else --sum; if(!pos) ++qian[sum+n]; else ans+=qian[sum+n-1]; } cout<<ans<<endl; return 0; }
牛客算法竞赛入门课第三节例题、习题 文章被收录于专栏
~很懒