题目链接

非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意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. hdu6060[贪心+dfs] 2017多校3

    /* hdu6060[贪心+dfs] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long L ...

  2. 【Luogu】P2759奇怪的函数(二分)

    题目链接 看了题解之后突然发现这题简直是水题.然而不看题解就想不出来.为什么呢? len(x)=log10(x)+1 于是二分寻找x. #include<iostream> #includ ...

  3. 论文笔记:Ten years of pedestrian detection, what have we learned?

    最近正在研究行人检测,学习了一篇2014年发表在ECCV上的一篇综述性的文章,是对行人检测过去十年的一个回顾,从dataset,main approaches的角度分析了近10年的40多篇论文提出的方 ...

  4. 二分图最小覆盖的Konig定理及其证明,最小的覆盖证明

    [转http://www.cppblog.com/abilitytao/archive/2009/09/02/95147.html  ->  http://yejingx.ycool.com/p ...

  5. ElasticSearch 多索引

    1.用逗号将索引隔开,如: $ curl -XPOST http://localhost:9200/aaa,website/_search/ { "took": 1, " ...

  6. 16.1112 模拟考试 T1

    加密[问题描述]有一种不讲道理的加密方法是: 在字符串的任意位置随机插入字符. 相应的,不讲道理的解密方法就是从字符串中恰好删去随机插入的那些字符.给定原文s和加密后的字符串t,求?有多少子串可以通过 ...

  7. 【HDOJ5948】Thickest Burger(签到)

    题意:不知道 思路:队友写的 #include <stdio.h> #include <vector> #include <algorithm> #include ...

  8. JS设置页面中方法执行一次的思想

    思想:在JS中定义一全局变量,在方法执行的时候根据全局变量的值判断是否需要执行,在方法中修改全局变量的值,可以使得方法只执行一次.: 例如: 定义全局变量: var isLoad = false;// ...

  9. hdu 4882 /按排顺序使序列最优问题

    题意: 安排一个序列,该序列每个数有俩个属性:t[i].val[i].计算一个点的价值:到目前为止的总时间*val[i].,,求  安排顺序后使得 计算所有点的价值之和最小. 思路:对于任意相邻俩项, ...

  10. [Bzoj5254][Fjwc2018]红绿灯(线段树)

    5254: [Fjwc2018]红绿灯 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 31  Solved: 24[Submit][Status][D ...