题目链接

非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意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(线段树+扫描线)的更多相关文章

  1. 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 ...

  2. POJ 2482 Stars in Your Window 线段树

    如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其 ...

  3. POJ 2482 Stars in Your Window (线段树区间合并+扫描线)

    这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用)  题意就是在平面上给你一些星 ...

  4. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  5. poj 2482 Stars in Your Window + 51Nod1208(扫描线+离散化+线段树)

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13196   Accepted:  ...

  6. POJ 2482 Stars in Your Window(线段树)

    POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...

  7. poj 2482 Stars in Your Window(扫描线)

    id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...

  8. POJ 2482 Stars in Your Window 离散化+扫描法 线段树应用

    遇见poj上最浪漫的题目..题目里图片以上几百词为一篇模板级英文情书.这情感和细腻的文笔深深地打动了我..不会写情书的童鞋速度进来学习.传送门 题意:坐标系内有n个星星,每个星星都有一个亮度c (1& ...

  9. POJ 2482 Stars in Your Window (线段树+扫描线+区间最值,思路太妙了)

    该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/ts ...

随机推荐

  1. pytorch将cpu训练好的模型参数load到gpu上,或者gpu->cpu上

    假设我们只保存了模型的参数(model.state_dict())到文件名为modelparameters.pth, model = Net() 1. cpu -> cpu或者gpu -> ...

  2. Relay Race (DP)

    Furik and Rubik take part in a relay race. The race will be set up on a large square with the side o ...

  3. 2017 Multi-University Training Contest - Team 4

    日常绝望系列 Questionnaire HDU - 6075 In order to get better results in official ACM/ICPC contests, the te ...

  4. HDU 4417 Super Mario(划分树问题求不大于k的数有多少)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. python ConfigParser 学习

    [安装] ConfigParser 是解析配置文件的第三方库,需要安装 pip install ConfigParser   [介绍] ConfigParser 是用来读取配置文件(可以是.conf, ...

  6. BZOJ 1197: [HNOI2006]花仙子的魔法【DP】

    Description 相传,在天地初成的远古时代,世界上只有一种叫做“元”的花.接下来,出 现了一位拥有魔法的花仙子,她能给花附加属性,从此,“元”便不断变异,产生了大千世界千奇百怪的各种各样的花. ...

  7. P3102 [USACO14FEB]秘密代码Secret Code

    题目描述 Farmer John has secret message that he wants to hide from his cows; the message is a string of ...

  8. POJ 2096 (dp求期望)

    A - Collecting Bugs Time Limit:10000MS     Memory Limit:64000KB     64bit IO Format:%I64d & %I64 ...

  9. .NET Core 3.0之创建基于Consul的Configuration扩展组件

    写在前面 经过前面三篇关于.NET Core Configuration的文章之后,本篇文章主要讨论如何扩展一个Configuration组件出来.如果前面三篇文章没有看到,可以点击如下地址访问 .N ...

  10. SELinux 服务检查与关闭

    查看SELinux状态: 1./usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态 SELinux status:         ...