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 ...
随机推荐
- HDU 1032.The 3n + 1 problem【注意细节】【预计数据不强】【8月21】
The 3n + 1 problem Problem Description Problems in Computer Science are often classified as belongin ...
- 白帽子讲web安全读后感
又是厚厚的一本书,为了不弄虚做假,只得变更计划,这一次调整为读前三章,安全世界观,浏览器安全和xss.其它待用到时再专门深入学习. 吴翰清是本书作者,icon是一个刺字,圈内人称道哥.曾供职于阿里,后 ...
- Mac OS安装Scrapy
个人觉得掌握简单的爬虫知识非常有用,特别是想要从一些特定网站自动地下载一些资源或者统计一些数据,非常的有用.对于产品经理来说,如果要了解竞争产品.替代产品的价格,可以写一个爬虫脚本从各大电商网站爬取相 ...
- 1250太小了 mysql 并发
SHOW VARIABLES LIKE '%connection%'; character_set_connection utf8mb4collation_connection utf8mb4_gen ...
- 浅谈HTTPS连接
相信很多朋友都遇到过网页被强插广告的情况,好端端一个干净的页面,动不动就被插了个屠龙宝刀点击就送的小窗口,看着就心烦.这种网页劫持强插广告的现象,在中国非常常见,往往是运营商进行HTTP劫持所造成的. ...
- UICollectionView基础用法
初始化部分: UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc]init]; self.myColl ...
- SQL 和 NoSQL 比较
定义: SQL (Structured Query Language) 数据库,指关系型数据库.主要代表:SQL Server,Oracle,MySQL(开源),PostgreSQL(开源). NoS ...
- 鼠标滑过TAB选项卡切换demo 可拓展
<html> <head> <script type="text/javascript"> <!-- function ShowTabs( ...
- Fabric原理剖析
Fabric架构 image.png Fabric网络 image.png Fabric模块 image.png Fabric交易流 根据Hyperledger Fabric 1.0架构, ...
- Java数据库操作类演示
只在mysql上测试过,不知道算不算好使1. [代码][Java]代码 package org.load.demo; import java.io.IOException;import ja ...