bzoj1246(树状数组)
来源:互联网 发布:东方财富网 知乎 编辑:程序博客网 时间:2024/06/11 04:30
树状数组的灵活运用,维护的是最大值,因为整个数组就是一个前缀最大值,所以可以用实现,求一个前缀最大值,和更新pos之后的最大值。
很好的运用,多回顾思考
#include<cstdio>#include<cmath>#include<cstdlib>#include<algorithm>#include<cstring>using namespace std;const int N=20005;int n;int pos[N][6];int t[N*5],b[N*5];void updata(int i,int x){while (i<=n*5){t[i]=max(t[i],x);i+= i&-i ;}}int query(int i){int ans=0;while (i){ans=max(ans,t[i]);i-=i&-i;}return ans;}int main(){scanf("%d",&n);for (int x,i=1;i<=n*5;i++){scanf("%d",&x);pos[x][++pos[x][0]]=i;}for (int i=1;i<=n*5;i++) scanf("%d",&b[i]);for (int i=1;i<=n*5;i++){for (int j=5;j;j--){int p=pos[b[i]][j],tmp;tmp=max(query(p),query(p-1)+1);updata(p,tmp);}}printf("%d",query(n*5));return 0;}
0 0
- bzoj1246(树状数组)
- (转)树状数组
- 树状数组(转载)
- Stars(树状数组)
- 树状数组(interval)
- (转)树状数组
- 树状数组(2)
- 树状数组(3)
- 树状数组(4)
- 树状数组(5)
- 树状数组(6)
- poj2352Stars(树状数组)
- POJ2299(树状数组)
- hdu2492 (树状数组)
- 树状数组()
- LA4329(树状数组)
- poj3468(树状数组)
- 【树状数组(一)】
- curl模拟请求
- 欢迎使用CSDN-markdown编辑器
- Path之PathMeasure的介绍(一)
- 大话设计模式总结【第一遍】(部分1)
- 记录错误.../Android/sdk/build-tools/21.1.2/aapt'' finished with non-zero exit value 1
- bzoj1246(树状数组)
- 网络通讯
- 移动微小的距离,线段相交,计算几何(怪物陷阱,LA 2797)
- form提交,如果某个input不在form标签内,后台是获取不到该input的值的。
- QT中Phonon音频播放用按钮实现前进后退几秒
- https://github.com/b3log/solo/wiki/standalone_mode
- Openlayers之地图的基本操作
- Android五种隐藏状态栏和标题栏的方法(隐藏状态栏、标题栏方法汇总)
- 9.表单