线段树+离散化+扫描线

AC之后,又认真读了一遍题目,好文章。

#include<cstdio>
#include<map>
#include<algorithm>
using namespace std; const int maxn=+;
int n;
long long W,H;
long long x[maxn],y[maxn],v[maxn];
struct seg
{
long long X;
long long Y1,Y2;
long long val;
}s[*maxn];
struct SegTree
{
long long MAX;
long long add;
}segTree[*maxn]; map<long long,int>m;
long long M[maxn];
int k; bool cmp(const seg&a,const seg&b)
{
if(a.X==b.X) return a.val>b.val;
return a.X<b.X;
} void pushUp(int rt)
{
segTree[rt].MAX=max(segTree[*rt].MAX,segTree[*rt+].MAX);
} void pushDown(int rt)
{
if(segTree[rt].add)
{
segTree[*rt].add+=segTree[rt].add;
segTree[*rt+].add+=segTree[rt].add;
segTree[*rt].MAX+=segTree[rt].add;
segTree[*rt+].MAX+=segTree[rt].add;
segTree[rt].add=;
}
} void build(int l,int r,int rt)
{
segTree[rt].add=;
segTree[rt].MAX=;
if(l==r) return; int m=(l+r)/;
build(l,m,*rt);
build(m+,r,*rt+);
} void update(long long val,int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
segTree[rt].add+=val;
segTree[rt].MAX+=val;
return;
} pushDown(rt);
int m=(l+r)/;
if(L<=m) update(val,L,R,l,m,*rt);
if(R>m) update(val,L,R,m+,r,*rt+);
pushUp(rt);
} void lsh()
{
m.clear();
k=;
for(int i=;i<=n;i++)
{
if(m[y[i]]==)
{
m[y[i]]=;
M[k++]=y[i];
}
if(m[y[i]+H-]==)
{
m[y[i]+H-]=;
M[k++]=y[i]+H-;
}
}
sort(M,M+k);
//m.clear(); 这个地方比较奇葩。清空了会TLE。。。。
for(int i=;i<k;i++) m[M[i]]=i+;
} int main()
{
//freopen("F:\\in.txt","r",stdin);
while(~scanf("%d%lld%lld",&n,&W,&H))
{
for(int i=;i<=n;i++) scanf("%lld%lld%lld",&x[i],&y[i],&v[i]);
lsh();
int tot=;
for(int i=;i<=n;i++)
{
s[tot].X=x[i];
s[tot].Y1=m[y[i]];
s[tot].Y2=m[y[i]+H-];
s[tot].val=v[i];
tot++; s[tot].X=x[i]+W-;
s[tot].Y1=m[y[i]];
s[tot].Y2=m[y[i]+H-];
s[tot].val=-v[i];
tot++;
} sort(s,s+tot,cmp); build(,k,); long long max_val=; for(int i=;i<tot;i++)
{
update(s[i].val,s[i].Y1,s[i].Y2,,k,);
max_val=max(segTree[].MAX,max_val);
}
printf("%lld\n",max_val);
}
return ;
}

POJ 2482 Stars in Your Window的更多相关文章

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

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

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

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

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

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

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

  5. (中等) POJ 2482 Stars in Your Window,静态二叉树。

    Description Here comes the problem: Assume the sky is a flat plane. All the stars lie on it with a l ...

  6. poj 2482 Stars in Your Window (线段树:区间更新)

    题目链接:http://poj.org/problem?id=2482 读完题干不免有些心酸(

  7. POJ 2482 Stars in Your Window(扫描线+线段树)

    [题目链接] http://poj.org/problem?id=2482 [题目大意] 给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和, 在矩形边缘的点不计算在内 [题解] ...

  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. LINQ&EF in 用算的写法 like

  2. Modal视图弹出方式

    Modal方式弹出页面: 1.Modal方式弹出页面在iOS中有很广泛的应用,比如UIImagePickerController等,Modal方式主要有以下几个作用: 检查登陆信息,Modal出登陆页 ...

  3. HttpCookie类

    转自:http://www.cnblogs.com/kissdodog/archive/2013/01/08/2851937.html HttpCookie类专门由C#用于读取和写入Cookie的类. ...

  4. VS2008 安装后没有模板

    VS2008 安装过程没有任何报错  启动VS2008,新建项目时就成了这样,没有任何模板: 解决方法: 开始 –> 程序 –> Microsoft Visual Studio 2008– ...

  5. springmvc 关于controller的字符编码

    在使用springMVC框架构建web应用,客户端常会请求字符串.整型.json等格式的数据,通常使用@ResponseBody注解使 controller回应相应的数据而不是去渲染某个页面.如果请求 ...

  6. 【jsp exception】如何处理jsp页面的错误

    根据jsp对错误的处理方式不同可以将其分为局部异常处理和全局异常处理.局部异常处理适用于个别jsp页面,当这些页面发生错误后,采取特殊的处理方式:全局异常处理适用于所有jsp页面,当所有页面发生某些指 ...

  7. Drivers Dissatisfaction

    Drivers Dissatisfaction time limit per test 4 seconds memory limit per test 256 megabytes input stan ...

  8. Beam me out!

    Beam me out! 题目描述 King Remark, first of his name, is a benign ruler and every wrongdoer gets a second ...

  9. WPF从我炫系列4---装饰控件的用法

    这一节的讲解中,我将为大家介绍WPF装饰控件的用法,主要为大家讲解一下几个控件的用法. ScrollViewer滚动条控件 Border边框控件 ViewBox自由缩放控件 1. ScrollView ...

  10. oracle 基础使用以及sql语句基础

        oracle的安装与卸载 要记住数据库口令,适用于sys.system.sysman/dbsnmp等账户,而scott帐号密码默认为tiger, 以oracle  10g来说,scott账户默 ...