(中等) POJ 2482 Stars in Your Window,静态二叉树。
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月16日 星期四 16时33分23秒
// File Name : 2482_1.cpp // 注意:建的不是完全二叉树,所以空间要开大,然后就是注意lc和rc的越界问题(不知如何判,所以直接初始化为0)。 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; #define lc (po<<1)
#define rc ((po<<1)|1) struct DE
{
int a,b,c; bool operator < (const DE &b) const
{
return c<b.c;
}
}de[MaxN]; int decou=; struct BIT
{
int N;
long long key[MaxN],val[MaxN];
long long *numP; long long SUM[MaxN],MAXN[MaxN]; void _build(int L,int R,int po)
{
if(L>R)
return; de[decou].a=L;
de[decou].b=R;
de[decou].c=po;
++decou; int M=(L+R+)>>; _build(L,M-,lc); key[po]=numP[M];
val[po]=;
SUM[po]=MAXN[po]=; _build(M+,R,rc);
} void build(long long *num,int cou)
{
N=cou;
numP=num;
memset(SUM,,sizeof(SUM));
memset(MAXN,,sizeof(MAXN));
_build(,N,);
} void pushUP(int po)
{
/* long long Lnum,Rnum,Rmaxn,Lmaxn; if(lc>N)
Lnum=Lmaxn=0;
else
{
Lnum=SUM[lc];
Lmaxn=MAXN[lc];
} if(rc>N)
Rnum=Rmaxn=0;
else
{
Rnum=SUM[rc];
Rmaxn=MAXN[rc];
} SUM[po]=Lnum+Rnum+val[po];
MAXN[po]=max(Lmaxn,max(Lnum+val[po]+Rmaxn,Lnum+val[po]));*/ SUM[po]=SUM[lc]+SUM[rc]+val[po];
MAXN[po]=max(MAXN[lc],SUM[lc]+val[po]+max(0LL,MAXN[rc]));
} void _add(int po,long long k,long long num)
{
// if(po>N)
// return; if(k==key[po])
val[po]+=num;
else if(k<key[po])
_add(lc,k,num);
else
_add(rc,k,num); pushUP(po);
} void add(long long k,long long num)
{
_add(,k,num);
} long long query()
{
return MAXN[];
} void display()
{
for(int i=;i<=N;++i)
cout<<key[i]<<' '<<val[i]<<' '<<SUM[i]<<' '<<MAXN[i]<<endl;
cout<<endl;
}
}; BIT tree; struct Point
{
long long x,y,val; bool operator < (const Point &b) const
{
if(x==b.x)
return y<b.y; return x<b.x;
}
}; Point P[MaxN];
int N;
long long W,H;
int cou;
long long num[MaxN];
long long ans; long long getans()
{
if(W== || H==)
return ; int Lp,Rp; Lp=Rp=; for(int i=;i<=N;++i)
{
while(Lp<=N && P[Lp].x<P[i].x)
{
tree.add(P[Lp].y,-P[Lp].val);
tree.add(P[Lp].y+H,P[Lp].val);
++Lp;
} while(Rp<=N && P[Rp].x<P[i].x+W)
{
tree.add(P[Rp].y,P[Rp].val);
tree.add(P[Rp].y+H,-P[Rp].val);
++Rp;
} ans=max(ans,tree.query());
} return ans;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(~scanf("%d %lld %lld",&N,&W,&H))
{
ans=;
cou=; for(int i=;i<=N;++i)
{
scanf("%lld %lld %lld",&P[i].x,&P[i].y,&P[i].val);
num[++cou]=P[i].y;
num[++cou]=P[i].y+H;
} sort(P+,P+N+);
sort(num+,num+cou+);
cou=unique(num+,num+cou+)-num-; tree.build(num,cou); printf("%lld\n",getans());
} return ;
}
(中等) POJ 2482 Stars in Your Window,静态二叉树。的更多相关文章
- poj 2482 Stars in Your Window(扫描线)
id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...
- POJ 2482 Stars in Your Window(线段树)
POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...
- poj 2482 Stars in Your Window + 51Nod1208(扫描线+离散化+线段树)
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13196 Accepted: ...
- POJ 2482 Stars in Your Window 线段树扫描线
Stars in Your Window Description Fleeting time does not blur my memory of you. Can it really be 4 ...
- poj 2482 Stars in Your Window (线段树:区间更新)
题目链接:http://poj.org/problem?id=2482 读完题干不免有些心酸(
- POJ 2482 Stars in Your Window(扫描线+线段树)
[题目链接] http://poj.org/problem?id=2482 [题目大意] 给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和, 在矩形边缘的点不计算在内 [题解] ...
- POJ 2482 Stars in Your Window 离散化+扫描法 线段树应用
遇见poj上最浪漫的题目..题目里图片以上几百词为一篇模板级英文情书.这情感和细腻的文笔深深地打动了我..不会写情书的童鞋速度进来学习.传送门 题意:坐标系内有n个星星,每个星星都有一个亮度c (1& ...
- POJ 2482 Stars in Your Window (线段树+扫描线+区间最值,思路太妙了)
该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/ts ...
- POJ 2482 Stars in Your Window
线段树+离散化+扫描线 AC之后,又认真读了一遍题目,好文章. #include<cstdio> #include<map> #include<algorithm> ...
随机推荐
- rollout
#! /bin/ksh # 设置环境变量 ############### ### UAT ### ############### export ENVS=/test/change/env/e ...
- oracle中触发器的讲解
触发器在数据库里以独立的对象存储,它与存储过程和函数不同的是,存储过程与函数需要用户显示调用才执行,而触发器是由一个事件来启动运行.即触发器是当某个事件发生时自动地隐式运行.并且,触发器不能接收参数. ...
- API CLOUD 快捷键
常用快捷键有:Ctrl+Z:撤销Ctrl+N:创建项目或文件Ctrl+Shift+F:代码格式化(这个经常用,可以美化代码,也可以通过这个检查代码是否出错)Ctrl+/ :注释和反注释Alt+/:强制 ...
- JPA 系列教程1-环境搭建
JPA JPA全称Java Persistence API. JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. Hibernate3.2+.Top ...
- Hibernate Session & Transaction详解
Hibernate Session & Transaction详解 HIbernate中的Session Session是JAVA应用程序和Hibernate进行交互时使用的主要接口,它也是持 ...
- KVO 进阶
Key-value coding (KVC) 和 key-value observing (KVO) 是两种能让我们驾驭 Objective-C 动态特性并简化代码的机制.在这篇文章里,我们将接触一些 ...
- ubuntu12.04的NFS配置
安装nfs: #sudo apt-get install nfs-kernel-server ubuntu12.04中的已经是最新版本了,无需安装 打开/etc/exports文件,在末尾加入: /h ...
- 17232 伪Acmer的推理(传递闭包)
17232 伪Acmer的推理 时间限制:1000MS 内存限制:65535K提交次数:0 通过次数:0 收入:0 题型: 编程题 语言: G++;GCC Description 现在正是期末, ...
- POJ 1365 Prime Land(整数拆分)
题意:感觉题意不太好懂,题目并不难,就是给一些p和e,p是素数,e是指数,然后把这个数求出来,设为x,然后让我们逆过程输出x-1的素数拆分形式,形式与输入保持一致. 思路:素数打表以后正常拆分即可. ...
- elasticsearch 性能调优
所有的修改都可以在elasticsearch.yml里面修改,也可以通过api来修改.推荐用api比较灵活 1.不同分片之间的数据同步是一个很大的花费,默认是1s同步,如果我们不要求实时性,我们可以执 ...