【Bzoj1303】中位数图
来源:互联网 发布:海沧广电网络客服 编辑:程序博客网 时间:2024/06/05 20:45
题意
给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b。中位数是指把所有元素从小到大排列后,位于中间的数。
解析
因为数都是不重复的,所以可以把左边小于它的记为+1,大于的记为-1,统计前缀和f。同理,右边大于的记为1,小于的记为-1,统计前缀和g,那么,如果左边某个数出现某次数的方法种数等于右边的,就根据乘法原理统计答案,特别地,f[0]=g[0]=1。数组下标要做一点处理。
#include <cstdio>#include <algorithm>#define Rep( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i<=(i##_END);i++)#define For( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i!=(i##_END);i++)#define Lop( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i>=(i##_END);i--)#define Dnt( i , _begin , _end ) for(int i=(_begin),i##_END=(_end);i!=(i##_END);i--)using std :: max;using std :: min;const int maxx = (100000<<1) + 25;const int N = 100005;int n,m,x,y,z;int a[maxx],f[maxx],g[maxx];int ans,tmp,pos;int main(){ scanf("%d%d",&n,&m); Rep( i , 1 , n ) scanf("%d",&a[i]); Rep( i , 1 , n ) if(a[i] == m) pos = i; f[N] = g[N] = 1; Dnt( i , pos-1 , 0 ) tmp += (a[i]<m)? 1 : -1,f[tmp+N] ++; tmp = 0; Rep( i , pos+1 , n ) tmp += (a[i]>m)? 1 : -1,g[tmp+N] ++; Rep( i , N-n , N+n ) ans += f[i]*g[i]; printf("%d",ans); return 0;}
阅读全文
0 0
- [BZOJ1303][CQOI2009]中位数图
- [BZOJ1303][CQOI2009]中位数图
- BZOJ1303[CQOI2009]中位数图
- [BZOJ1303] [CQOI2009]中位数图
- bzoj1303: [CQOI2009]中位数图
- bzoj1303[CQOI2009]中位数图
- [bzoj1303][CQOI2009]中位数图
- bzoj1303: [CQOI2009]中位数图
- 【Bzoj1303】中位数图
- bzoj1303 [CQOI2009]中位数图
- 【bzoj1303】[CQOI2009]中位数图
- [bzoj1303][数论]中位数图
- [BZOJ1303][CQOI2009]中位数图
- bzoj1303 [CQOI2009]中位数图
- bzoj1303: [CQOI2009]中位数图
- bzoj1303: [CQOI2009]中位数图
- BZOJ1303(CQOI2009)[中位数图]--奇技淫巧
- BZOJ1303 [CQOI2009]中位数图 【乱搞】
- 分布式数据库中间件对比总结
- lintcode(412)分糖果
- Alpha、Beta、RC、GA版本的区别
- java虚拟机---java内存模型
- FFMPEG学习【libavfilter】(一)
- 【Bzoj1303】中位数图
- servlet接收POST提交的中文传入数据库后乱码
- C#的zxing条码工具
- Linux 下 JDK + Eclipse + PyDev 安装与配置
- C primer plus 第四章总结
- 安卓应用升级、捕捉异常上报、运营统计
- 读
- 设计模式之适配器模式
- AT24CXX、DS1302、红外HS0038 20170610 周六