2016"百度之星" - 初赛(Astar Round2B)
2016-05-22 16:48
267 查看
1001 区间的价值:
RMQ+扫描法
我们预处理RMQ求任意区间的最大值
预处理出以a[i]为最小值 能向左延伸 向右延伸的 L[i], R[i]
那么对于 一个答案 (L[i], R[i]) *rmq(L[i],R[i]) 为此长度的答案,我们可以发现他是可以更新到小于其长度的所有长度答案的,更新就好
View Code
RMQ+扫描法
我们预处理RMQ求任意区间的最大值
预处理出以a[i]为最小值 能向左延伸 向右延伸的 L[i], R[i]
那么对于 一个答案 (L[i], R[i]) *rmq(L[i],R[i]) 为此长度的答案,我们可以发现他是可以更新到小于其长度的所有长度答案的,更新就好
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include<queue> #include<map> using namespace std; const int N = 1e5+20, M = 1e4, mod = 1000000007,inf = 1e9; typedef long long ll; int a ,b ,n,now ; int H ; ll ans ; int f ,h ; int main() { while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) scanf("%d",&a[i]),b[i] = a[i]; for(int i=1;i<=n;i+=1) { memset(f,0,sizeof(f)); memset(h,0,sizeof(h)); for(int j=1;j<=n;j++) if(a[i]==a[j]) now[j] = 0; else if(a[i]>a[j]) now[j] = 1; else if(a[i]<a[j]) now[j] = -1; int last = 0,mx = 0; ll aa = 1; for(int j=i-1;j>=1;j--) f[last+now[j]+M]++,last +=now[j],mx = max(mx,last); last = 0; for(int j=i+1;j<=n;j++) h[last+now[j]+M]++,last +=now[j],mx = max(mx,last); for(int j=1;j<=mx;j++) aa += ((ll)f[j+M]*(ll)h[-j+M]),aa+=((ll)f[-j+M]*(ll)h[j+M]); aa+=f[0+M]; aa+=h[0+M]; aa+=(ll)f[0+M]*(ll)h[0+M]; ans[i] = aa; } for(int i=1;i<n;i+=1) { printf("%I64d ",ans[i]); } printf("%I64d\n",ans ); } return 0; }
View Code
相关文章推荐
- php数组----初探谈任何语言恒古不变的是算法和思想谈与Java中的数组对比
- EventBus3.0使用
- 在jQueryEasyui datagrid加载完成后清除选中
- cookie 和 session
- 【BZOJ-2115】Xor 线性基 + DFS
- Python 资源大全中文版
- POJ 1276 多重背包+模板
- C++变量和对象的区别联系
- Android进程间通信(IPC)之Socket
- Android之记住密码与自动登陆实现
- web前端新手需要认识的CSS;css共有多少标签呢?
- Cube Stacking
- 软件工程个人作业12
- linux的脚本应用for循环答应变量
- Navicat连接Oracle11g 错误的解决办法
- Action属性值决定物理视图资源
- PAT螺旋方阵
- 反转一个单链表并输出
- map 有log n 的时间复杂度 map 有log n 的时间复杂度 map 有log n 的时间复杂度 map 有log n 的时间复杂度 map 有log n 的时间复杂度 map
- 基于STM32F429-Discovery USART1 PA9 PA10 调试成功。