POJ 2482 Stars in Your Window(线段树+扫描线)
非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序。
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define maxn 50100
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL __int64
struct node
{
LL lx,rx,y;
LL s;
node(){}
node(LL a,LL b,LL c,LL d):lx(a),rx(b),y(c),s(d){}
bool operator < (const node &S) const
{
if(y == S.y)
return s > S.s;
else
return y < S.y;
}
}mat[maxn];
LL que[*maxn];
LL tree[*maxn];
LL lz[*maxn];
void pushup(int rt)
{
tree[rt] = max(tree[rt<<],tree[rt<<|]);
}
void pushdown(int rt)
{
if(lz[rt])
{
lz[rt<<] += lz[rt];
lz[rt<<|] += lz[rt];
tree[rt<<] += lz[rt];
tree[rt<<|] += lz[rt];
lz[rt] = ;
}
}
void update(int L,int R,int c,int l,int r,int rt)
{
int m;
if(L <= l&&r <= R)
{
tree[rt] += c;
lz[rt] += c;
return ;
}
pushdown(rt);
m = (l+r)>>;
if(L <= m)
update(L,R,c,lson);
if(R > m)
update(L,R,c,rson);
pushup(rt);
}
int bin(LL x,int n)
{
int str,mid,end;
str = ;
end = n;
while(str <= end)
{
mid = (str+end)/;
if(que[mid] == x)
return mid;
else if(que[mid] > x)
end = mid - ;
else
str = mid + ;
}
return mid;
}
int main()
{
int n,num,k,i;
LL a,b,c,h,w;
while(scanf("%d%I64d%I64d",&n,&w,&h)!=EOF)
{
num = ;
w--;
h--;
for(i = ;i < n;i ++)
{
scanf("%I64d%I64d%I64d",&a,&b,&c);
mat[num] = node(a,a+w,b,c);
que[num++] = a;
mat[num] = node(a,a+w,b+h,-c);
que[num++] = a+w;
}
k = ;
sort(que,que+num);
sort(mat,mat+num);
for(i = ;i < num;i ++)
{
if(que[i] != que[i-])
que[k++] = que[i];
}
LL maxz = ;
memset(tree,,sizeof(tree));
memset(lz,,sizeof(lz));
for(i = ;i < num;i ++)
{
int l = bin(mat[i].lx,k-);
int r = bin(mat[i].rx,k-);
if(l <= r) update(l,r,mat[i].s,,k-,);
maxz = max(maxz,tree[]);
}
printf("%I64d\n",maxz);
}
return ;
}
POJ 2482 Stars in Your Window(线段树+扫描线)的更多相关文章
- 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 线段树
如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其 ...
- POJ 2482 Stars in Your Window (线段树区间合并+扫描线)
这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用) 题意就是在平面上给你一些星 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- 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(线段树)
POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...
- poj 2482 Stars in Your Window(扫描线)
id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...
- 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 ...
随机推荐
- Centos6.5搭建git远程仓库
远程仓库搭建 step1:安装git ```yum -y install git``` step2:创建用户git,用来运行git服务 useradd git passwd git //修改git用户 ...
- BZOJ 3450 Tyvj1952 Easy ——期望DP
维护$x$和$x^2$的期望递推即可 #include <map> #include <ctime> #include <cmath> #include <q ...
- 算法复习——cdq分治
题目: Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要 ...
- PHP文件上传类(页面和调用部分)
<!--upform.html内容--> <form action="upload.php" method="post" enctype=&q ...
- centos7如何查看ip信息(centos 6.5以前都可以用ifconfig 但是centos 7里面没有了,centos 7用什么查看?)
展开全部 centos7如何查看ip信息可以这样解决: 1.首先要先查看一下虚拟机的ip地址,因为ipconfig不是centos7,因此要使用 ip addr来查看. 2.查看之后你就会发现ens3 ...
- Virtualization基础
官方文档学习 https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/pdf/Virtualization_G ...
- SpringBoot整合freemarker中自定义标签获取字典表的数据
因为在前端要根据字典表中的数据去将1.2这些值转换成对应的文字解释 1.首先要创建一个类去实现 TemplateDirectiveModel 类 @Component public class Dic ...
- qq空间微博等更多社交平台分享
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- VC/MFC中计算程序运行时间
转自原文VC/MFC中计算程序运行时间 说明,这四种方法也分别代表了类似的实现,在MFC中,所可以从哪些类集合去考虑. 方法一 利用GetTickCount函数(ms) CString str; lo ...
- gdb生成的core文件位置
gdb可以生成core文件,记录堆栈信息,core文件名字是下面这种格式 :core.9488,其中9488是PID 文件位置是当前目录