错误记录:

题目说输入在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. html-基本form元素---ShinePans

    <html> <meta http-equiv="content-type" content="text/html;charset=UTF-8" ...

  2. Android 打造随意层级树形控件 考验你的数据结构和设计

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/40212367,本文出自:[张鸿洋的博客] 1.概述 大家在项目中或多或少的可能会 ...

  3. 代码书写C++ 中调用传递与指针传递根本区别

    从概念上讲.指针从本质上讲就是存放变量地址的一个变量,在逻辑上是独立的,它可以被改变,包括其所指向的地址的改变和其指向的地址中所存放的数据的改变.而引用是一个别名,它在逻辑上不是独立的,它的存在具有依 ...

  4. 3531: [Sdoi2014]旅行

    3531: [Sdoi2014]旅行 Time Limit: 20 Sec  Memory Limit: 512 MB Submit: 1731  Solved: 772 [Submit][Statu ...

  5. String,StringBuilder与StringBuffer的区别

    相信大家看到过很多比较String和StringBuffer区别的文章,也明白这两者的区别,然而自从Java 5.0发布以后,我们的比较列表上将多出一个对象了,这就是StringBuilder类.St ...

  6. gRPC错误码 http状态码 provide your APIs in both gRPC and RESTful style at the same time

    How gRPC error codes map to HTTP status codes in the response https://github.com/grpc-ecosystem/grpc ...

  7. Linux Linker

    文章原文:http://zhidao.baidu.com/link?url=U2Mtcc6BKi4vuQ1MO8U6s9gNm4y9Epphz03veA2lVpRWMozyVdj0PYvw1ZU9qj ...

  8. 哈希表---线性探测再散列(hash)

    //哈希表---线性探测再散列 #include <iostream> #include <string> #include <stdio.h> #include ...

  9. UVA11624 Fire! —— BFS

    题目链接:https://vjudge.net/problem/UVA-11624 题解: 坑点:“portions of the maze havecaught on fire”, 表明了起火点不唯 ...

  10. html5--6-63 布局

    html5--6-63 布局 实例 学习要点 掌握传统布局与CSS3新增布局方式的实现和应用 掌握CSS3新增属性box-sizing 了解CSS3新增的多列布局 常用布局方式 固定布局与流体布局的优 ...