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 ...
随机推荐
- Ubuntu Software Center has closed unexpectly解决方案
打开软件中心Ubuntu Software Center的时候 出现crash report :The application Ubuntu Software Center has closed un ...
- 九度oj 题目1262:Sequence Construction puzzles(I)_构造全递增序列
题目描述: 给定一个整数序列,请问如何去掉最少的元素使得原序列变成一个全递增的序列. 输入: 输入的第一行包括一个整数N(1<=N<=10000). 接下来的一行是N个满足题目描述条件的整 ...
- shell的while循环
while循环用于不断执行一系列命令,也用于从输入文件中读取数据:命令通常为测试条件.其格式为: while command do Statement(s) to be executed if ...
- Masonry练习
tableView的cell自动适应,scrollview自动适应,自定义自动布局控件 demo链接:http://pan.baidu.com/s/1jHsrGwQ
- 【bzoj4889】[Tjoi2017]不勤劳的图书管理员 树状数组+分块+二分
题目描述(转自洛谷) 加里敦大学有个帝国图书馆,小豆是图书馆阅览室的一个书籍管理员.他的任务是把书排成有序的,所以无序的书让他产生厌烦,两本乱序的书会让小豆产生这两本书页数的和的厌烦度.现在有n本被打 ...
- BZOJ 1072 [SCOI2007]排列perm ——状压DP
[题目分析] 没什么好说的,水题. 代码比较丑,结果需要开long long 时间爆炸 [代码] #include <cstdio> #include <cstring> #i ...
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- HP-Unix安装Memcache问题
安装环境 HP-UX 125RITEC B.11.31 U ia64 0942432495 gcc (GCC) 4.3.1 libevent-1.4.14b-stable.tar.gz memcach ...
- 对Netflix Ribbon的Loadbalancer类源码设计合理性的一点质疑
首先,这只是我个人的一点质疑,可能是因为我自己菜没有领悟到作者的意思,也正因此,想发出来跟大家一起探讨. 在昨晚,我因为在编写自己的开源项目的负载均衡模块(这是我开源项目的介绍:https://www ...
- HDU 1242 dFS 找目标最短路
//多个起点,要最短得目标,不妨倒过来从目标出发,去找最近的点更新!!!!!!递归时思路要清楚 #include<iostream> #include<cstring> usi ...