Stars in Your Window POJ - 2482
错误记录:
题目说输入在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的更多相关文章
- poj 2482 Stars in Your Window(扫描线)
id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...
- POJ 2482 Stars in Your Window(线段树)
POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- poj 2482 Stars in Your Window + 51Nod1208(扫描线+离散化+线段树)
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13196 Accepted: ...
- 51nod 1208 && POJ 2482:Stars in Your Window
1208 Stars in Your Window 题目来源: Poj 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 取消关注 整点上有N颗星星,每颗 ...
- 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 ...
- (中等) 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 ...
- [poj P2482] Stars in Your Window
[poj P2482] Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Description Fleeting time ...
- Stars in Your Window(线段树求最大矩形交)
题目连接 http://poj.org/problem?id=2482 Description Fleeting time does not blur my memory of you. Can it ...
随机推荐
- Unity自己主动打包工具
最開始有写打包工具的想法,是由于看到<啪啪三国>王伟峰分享的一张图,他们有一个专门的"工具程序猿"开发各种工具. (ps:说起来这个王伟峰和他的创始团队成员,曾经跟我是 ...
- 网络基础 二 (TCP协议代码,UDP协议代码)
TCP 三次握手,四次断开 三次握手(必须先由客户端发起) 客户端:发送请求帧给服务器. 服务器:收到客户端的请求,并回复可以建立连接 客户端:与服务器建立连接 四次断开 (谁先发起都行,以客户端为 ...
- RedHat 安装Hadoop并运行wordcount例子
1.安装 Red Hat 环境 2.安装JDK 3.下载hadoop2.8.0 http://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/had ...
- mysql 数据库连接
1.需要mysql驱动包:mysql-connector-java-5.1.7-bin.jar 2. package com.jmu.ccjoin.web.controller; import jav ...
- KbmMW资源汇总(特别是xalion的文章)
KbmMW框架是收费的,不在此提供下载,如需购买,请自行联系作者Kim Madsen. 网址资源: 官网主页:http://www.components4programmers.com/product ...
- GPS常见故障
当出现故障时,依据可能原因进行排查. 下表列举典型故障及调试方法 现象 root cause 检查 实验 GPS无法开启/无法搜星 软件配置错误 SW 相关配置(如GPIO等) 录制mobile ...
- HDU1495 非常可乐 —— BFS + 模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1495 非常可乐 Time Limit: 2000/1000 MS (Java/Others) M ...
- codeforces 437A. The Child and Homework 解题报告
题目链接:http://codeforces.com/problemset/problem/437/A 题目意思:给出四个选项A.B.C.D选项的内容描述,要求选出符合以下条件的一项. (1)如果某个 ...
- string类中运算符重载实现
C++中预定义的加.减等运算符的操作对象只能是基本的数据类型.如果要在用户自定义的类型对象上应用同样的运算符,就需要通过运算符重载来重新定义其实现,使它能够用于自定义类型执行特定的操作,所以运算符重载 ...
- java前端学习步骤
前端说的比较好的知乎:https://www.zhihu.com/question/22759296 网站开发绝杀技:https://ke.qq.com/course/20945?from=qqcha ...