FZU Problem 2136 取糖果(线段树离散化,区间合并)
来源:互联网 发布:javascript怎么发音 编辑:程序博客网 时间:2024/06/06 02:15
Problem 2136 取糖果
Accept: 175 Submit: 499
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
有N个袋子放成一排,每个袋子里有一定数量的糖果,lzs会随机选择连续的几个袋子,然后拿走这些袋子中包含最多糖果的袋子。现问你,在选择x个袋子的情况下,lzs最坏情况下,也就是最少会拿到多少个糖果?对于x取值为1到n都分别输出答案。
Input
第一行一个整数T,表示有T组数据。
每组数据先输入一行一个整数N(1<=N<=100000),表示袋子数,接下来一行输入N个正整数,输入的第i个数表示第i个袋子所装的糖果数。
Output
每组数据输出n行,第i行表示lzs随机取连续的i个袋子时的最坏情况下能拿到的糖果数。
Sample Input
151 3 2 4 5
Sample Output
13345
Submit Back Status Discuss
超时一遍,,换了种离散化的方法过了。。
ac代码
6465702015-12-07 16:10:15Accepted2136Visual C++515 ms6064KB2215Bkxh1995
#include<stdlib.h>#include<algorithm>#include<iostream>#include<stdio.h>#include<string.h>#define N 100050using namespace std;struct s{ int lx,rx,mx;}node[N<<2];int a[N];void build(int l,int r,int tr){ node[tr].lx=node[tr].rx=node[tr].mx=0; if(l==r) return; int mid=(l+r)>>1; build(l,mid,tr<<1); build(mid+1,r,tr<<1|1);}/*int bseach(int val,int n){ int l=1; int r=n; while(l<=n) { int mid=(l+r)>>1; if(b[mid]==val) return mid; if(b[mid]>val) { r=mid-1; } else l=mid+1; } return l;}*/struct S{ int val,id;}b[N];int cmp(S a,S b){ return a.val<b.val;}void pushup(int tr,int l,int r){ int m=(r-l)+1; if(node[tr<<1].lx==(m-(m>>1))) node[tr].lx=node[tr<<1].lx+node[tr<<1|1].lx; else node[tr].lx=node[tr<<1].lx; if(node[tr<<1|1].rx==(m>>1)) node[tr].rx=node[tr<<1|1].rx+node[tr<<1].rx; else node[tr].rx=node[tr<<1|1].rx; node[tr].mx=max(node[tr<<1].mx,node[tr<<1|1].mx); node[tr].mx=max(node[tr].mx,node[tr<<1].rx+node[tr<<1|1].lx);}void update(int pos,int val,int l,int r,int tr){ if(l==r) { node[tr].mx=val; node[tr].lx=val; node[tr].rx=val; return; } int mid=(l+r)>>1; if(pos<=mid) update(pos,val,l,mid,tr<<1); else update(pos,val,mid+1,r,tr<<1|1); pushup(tr,l,r);}int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int i; for(i=1;i<=n;i++) { scanf("%d",&a[i]); b[i].val=a[i]; b[i].id=i; } //sort(b+1,b+num+1); //int n=unique(b+1,b+num+1)-(b+1); sort(b+1,b+1+n,cmp); build(1,n,1); int j=1; for(i=1;i<=n;i++) { while(node[1].mx<i) { //int x=bseach(a[j++],n); update(b[j++].id,1,1,n,1); } printf("%d\n",b[j-1].val); } }}
0 0
- FZU Problem 2136 取糖果(线段树离散化,区间合并)
- FZU 2136 取糖果(线段树)
- fzu 2136 取糖果(线段树)
- fzu 11月赛E 2136 取糖果 线段树
- FZU 2136 取糖果
- FZU 2136 取糖果
- URAL 1019. Line Painting 线段树 区间合并 离散化
- poj2528 线段树 区间合并 特殊离散化
- UVA 11235 线段树区间合并 & 离散化
- FZU Problem 2136 取糖果 2种做法
- hdu 1199 Color the Ball (线段树区间合并,离散化)
- 【NOI2016】区间(线段树+离散化)
- FZU 2136 取糖果 (排序+并查集)
- 线段树 (区间合并)
- 【单调栈】fzu 2136取糖果
- 线段树:CDOJ1592-An easy problem B (线段树的区间合并)
- 线段树+区间压缩映射(离散化)
- XTUOJ 区间覆盖总长(线段树+离散化)
- (完美亲测)可行的安卓手机一键修改型号的教程
- 第14周项目1-验证折半查找算法(1)
- Uincode和ASCLL
- Dubbo架构设计详解
- qemu numa nodes passthrough
- FZU Problem 2136 取糖果(线段树离散化,区间合并)
- Error: Please renew the default configurations.
- Linux中修改Mysql root用户密码的方法
- 第十四周项目1-验证折半查找
- 1、osgViewer::Viewer,osgViewer::ViewerBase,osgGA::KeySwitchMatrixManipulator,osg::ArgumentParser的说明
- 第十五周上机实践—项目1(1)—哈希表算法的验证
- Javascript闭包的用途
- Akka Cluster原理与应用
- activemq 持久化