错误记录:

题目说输入在int范围内,但是运算过程中可能超int;后来开了很多longlong就过了

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
struct Q
{
ll x1,x2,y;int c,type;
}q[];
int nq;
bool operator<(const Q &a,const Q &b)
{
return a.y<b.y||(a.y==b.y&&a.type<b.type);
}
int n,w,h;
ll ans;
namespace S
{
#define lc (num<<1)
#define rc (num<<1|1)
#define mid (l+((r-l)>>1))
ll d[],addv[];
void build(int l,int r,int num)
{
if(l==r) {d[num]=addv[num]=;return;}
build(l,mid,lc);build(mid+,r,rc);
d[num]=addv[num]=;
}
int L,R;ll x;
void pd(int l,int r,int num)
{
d[lc]+=addv[num];d[rc]+=addv[num];
addv[lc]+=addv[num];addv[rc]+=addv[num];
addv[num]=;
}
void _addx(int l,int r,int num)
{
if(L<=l&&r<=R)
{
d[num]+=x;addv[num]+=x;
return;
}
pd(l,r,num);
if(L<=mid) _addx(l,mid,lc);
if(mid<R) _addx(mid+,r,rc);
d[num]=max(d[lc],d[rc]);
}
ll _que(int l,int r,int num)
{
if(L<=l&&r<=R) return d[num];
pd(l,r,num);
ll ans=;
if(L<=mid) ans=max(ans,_que(l,mid,lc));
if(mid<R) ans=max(ans,_que(mid+,r,rc));
return ans;
}
#undef lc
#undef rc
#undef mid
}
map<ll,ll> ma;
ll t0[];
int main()
{
int i;ll a,b,c;
while(scanf("%d%d%d",&n,&w,&h)==)
{
nq=;
for(i=;i<=n;i++)
{
scanf("%lld%lld%lld",&a,&b,&c);
q[++nq].y=a-w+;q[nq].x1=b-h+;q[nq].x2=b;q[nq].c=c;q[nq].type=;
q[++nq].y=a+;q[nq].x1=b-h+;q[nq].x2=b;q[nq].c=c;q[nq].type=;
}
ans=;
t0[]=;
for(i=;i<=nq;i++) t0[++t0[]]=q[i].x1,t0[++t0[]]=q[i].x2;
sort(t0+,t0+t0[]+);t0[]=unique(t0+,t0+t0[]+)-t0-;
ma.clear();
for(i=;i<=t0[];i++) ma[t0[i]]=i;
for(i=;i<=nq;i++) q[i].x1=ma[q[i].x1],q[i].x2=ma[q[i].x2];
sort(q+,q+nq+);
S::build(,t0[],);
for(i=;i<=nq;i++)
{
if(q[i].type==)
{
S::L=q[i].x1;S::R=q[i].x2;S::x=-q[i].c;
S::_addx(,t0[],);
}
else
{
S::L=q[i].x1;S::R=q[i].x2;S::x=q[i].c;
S::_addx(,t0[],);
}
if(i==nq||q[i].y!=q[i+].y)
{
S::L=;S::R=t0[];
ans=max(ans,S::_que(,t0[],));
}
}
printf("%lld\n",ans);
}
return ;
}

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

  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(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

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

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

  5. 51nod 1208 && POJ 2482:Stars in Your Window

    1208 Stars in Your Window 题目来源: Poj 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题  收藏  取消关注 整点上有N颗星星,每颗 ...

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

  7. (中等) 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 ...

  8. [poj P2482] Stars in Your Window

    [poj P2482] Stars in Your Window Time Limit: 1000MS  Memory Limit: 65536K Description Fleeting time ...

  9. Stars in Your Window(线段树求最大矩形交)

    题目连接 http://poj.org/problem?id=2482 Description Fleeting time does not blur my memory of you. Can it ...

随机推荐

  1. C++类中使用new及delete小例子(续)

    在该示例中我们显式定义了复制构造函数来代替默认复制构造函数, 在该复制构造函数的函数体内, 不是再直接将源对象所申请空间的地址赋值给被初始化的对象, 而是自己独立申请一处内存后再将源对象的属性复制过来 ...

  2. C++ 模板应用浅析

    把曾经写的C++模板的应用心得发表出来. 回忆起当时在学习C++模板时的无助和恐惧,如今还心有余悸.我分享出来我的心得,仅仅希望别人少走弯路,事实上它就这么几种使用方法,不须要害怕. 我总结了模板的四 ...

  3. 深入浅出 - Android系统移植与平台开发(九)- Android系统system_server及Home启动

    3.3 Zygote守护进程与system_server进程 Android的执行环境和Java执行环境有着本质的差别,在Android系统中每一个应用程序都是一独立的进程,当一个进程死掉时,不会影响 ...

  4. redis中键值对中值的各种类型

    1 value的最基本的数据类型是String 2 如果value是一张图片 先对图片进行base64编码成一个字符串,然后再保存到redis中,用的时候进行base64解码即可. 这是base64的 ...

  5. EventStore文件存储设计

    背景 ENode是一个CQRS+Event Sourcing架构的开发框架,Event Sourcing需要持久化事件,事件可以持久化在DB,但是DB由于面向的是CRUD场景,是针对数据会不断修改或删 ...

  6. Java 三大特性:封装、继承、多态

    一.封装: 对内 可封装自己的实现细节,使之信息隐藏不被其它类破坏: 对外 各个类之间分工明确, 其它类无需关心实现细节,类中细节发生改变,其它类也无需作出更改: 二.继承: 从已有的类中派生出新的类 ...

  7. noip2016前的话[漫谈]

    今天是11月15日,离noip2016还剩三天: 今年我也是高二了,回首一下去年的时光,真的仿佛仍在昨天,我甚至现在还清楚的记得,当年那次我们做的每一件事: 星期五,回去与室友告别,得到了祝愿,乘公交 ...

  8. wukong引擎源码分析之索引——part 3 文档评分 无非就是将docid对应的fields信息存储起来,为搜索结果rank评分用

    之前的文章分析过,接受索引请求处理的代码在segmenter_worker.go里: func (engine *Engine) segmenterWorker() { for { request : ...

  9. 百度地图API应用之获取用户的具体位置

    功能的大概:用户通过点击地图上面的位置,在地图上面进行描点,然后再把获取的到的地理位置保存到地图上面的地址栏目中. 主要是百度地图API的使用 .代码如下: var map = new BMap.Ma ...

  10. SPOJ:Collecting Candies(不错的DP)

    Jonathan Irvin Gunawan is a very handsome living person. You have to admit it to live in this world. ...