HDU 4908/BC B BestCoder Sequence
来源:互联网 发布:政府网站建申办域名 编辑:程序博客网 时间:2024/05/17 23:45
题意概括求以m为中位数的子区间有多少个,注意到数列是1~n的,m只会出现一次,那么我们要统计的子区间一定是包涵m的,只要统计m的每一侧,每个以m为界的区间,有多少比m大和比m小的就可以了,可以直接记录其差值,那么左右两区间对应就应该是互为相反数。用map统计下即可
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include<list>#include<set>#include<map>#include<stack>#include<queue>#include<deque>#define mem(x,y) memset(x,y,sizeof(x))#define pb push_backusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int,double> pii;#define bug puts("===========");#define zjc puts("");const double pi=(acos(-1.0));const double eps=1e-8;const ll INF=1e18+10;const ll inf=1e9+10;const int mod=1e9+7;const int maxn=40000+10;/*=======================================*/map<int,int>mp;int a[maxn];int main(){ int n,m; while(~scanf("%d%d",&n,&m)){ int id; for(int i=1;i<=n;i++) { scanf("%d",a+i); if(a[i]==m) id=i; } mp.clear(); int cnt=0; mp[0]++; for(int i=id-1;i>0;i--){ if(a[i]>m) cnt++; else cnt--; mp[cnt]++; } ll ans=0; cnt=0; for(int i=id+1;i<=n;i++){ if(a[i]>m) cnt++; else cnt--; ans+=mp[-cnt]; } printf("%I64d\n",ans+mp[0]); } return 0;}
0 0
- HDU 4908/BC B BestCoder Sequence
- 【CUGBACM15级BC第三场 B】hdu 4908 BestCoder Sequence
- hdu 4908 BestCoder Sequence
- hdu 4908 BestCoder Sequence
- HDU 4908 BestCoder Sequence
- hdu 4908 BestCoder Sequence
- HDU 4908 BestCoder Sequence
- hdu 4908 BestCoder Sequence
- hdu 4908 BestCoder Sequence
- HDU 4908 BestCoder Sequence
- HDU 4908BestCoder Sequence
- HDU 4908 (杭电 BC #3 1002题)BestCoder Sequence(DP)
- 【HDU】4908 BestCoder Sequence 预处理
- hdu 4908 BestCoder Sequence(计数)
- hdu 4908 BestCoder Sequence【DP】
- HDU 4908 BestCoder Sequence (hash)
- hdu 4908 BestCoder Sequence 策略
- HDU 4908 BestCoder Sequence 思维
- Linux下的C语言开发(开篇)
- python解码问题
- VanlOS 10 发布
- java反射机制详解 及 Method.invoke解释
- Java使用freemarker模版发送包含图片邮件
- HDU 4908/BC B BestCoder Sequence
- 深入理解Java:注解(Annotation)自定义注解入门
- eclipse中配置tomcat 启动正常 访问报404
- css总结
- eclipse优化设置介绍---谷营中西
- 在CentOS中搭建ftp服务器出现的问题
- 数据结构——模拟集合的实现(2)
- JAVA并发编程(二)内置锁和对象共享
- PTA PAT Judge 【模拟题,未完待续】