【POJ 2482】 Stars in Your Windows
【题目链接】
http://poj.org/problem?id=2482
【算法】
线段树 + 扫描线
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 10010
typedef long long ll; struct info
{
ll x,l,r,v;
} a[MAXN<<]; ll i,n,w,h,len,lth,ans,l,r;
ll x[MAXN],y[MAXN],c[MAXN],val[MAXN<<]; struct SegmentTree
{
struct Node
{
ll l,r;
ll mx,tag;
} Tree[MAXN<<];
inline void build(ll index,ll l,ll r)
{
ll mid;
Tree[index].l = l; Tree[index].r = r;
Tree[index].mx = ;
if (l == r) return;
mid = (Tree[index].l + Tree[index].r) >> ;
build(index<<,l,mid);
build(index<<|,mid+,r);
}
inline void update(ll index)
{
Tree[index].mx = max(Tree[index<<].mx,Tree[index<<|].mx);
}
inline void pushdown(ll index)
{
if (Tree[index].tag)
{
Tree[index<<].mx += Tree[index].tag;
Tree[index<<|].mx += Tree[index].tag;
Tree[index<<].tag += Tree[index].tag;
Tree[index<<|].tag += Tree[index].tag;
Tree[index].tag = ;
}
}
inline void add(ll index,ll l,ll r,ll val)
{
ll mid;
if (l > r) return;
if (Tree[index].l == l && Tree[index].r == r)
{
Tree[index].mx += val;
Tree[index].tag += val;
} else
{
pushdown(index);
mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) add(index<<,l,r,val);
else if (mid + <= l) add(index<<|,l,r,val);
else
{
add(index<<,l,mid,val);
add(index<<|,mid+,r,val);
}
update(index);
}
}
inline ll get()
{
return Tree[].mx;
}
} T;
inline bool cmp(info a,info b)
{
return (a.x != b.x) ? (a.x < b.x) : (a.v < b.v);
} int main()
{ while (scanf("%lld%lld%lld",&n,&w,&h) != EOF)
{
len = lth = ans = ;
for (i = ; i <= n; i++)
{
scanf("%lld%lld%lld",&x[i],&y[i],&c[i]);
a[++len] = (info){x[i],y[i],y[i]+h,c[i]};
a[++len] = (info){x[i]+w,y[i],y[i]+h,-c[i]};
val[++lth] = y[i];
val[++lth] = y[i] + h;
}
sort(val+,val+lth+);
lth = unique(val+,val+lth+) - val - ;
sort(a+,a+len+,cmp);
T.build(,,lth);
for (i = ; i <= len; i++)
{
l = lower_bound(val+,val+lth+,a[i].l) - val;
r = lower_bound(val+,val+lth+,a[i].r) - val - ;
T.add(,l,r,a[i].v);
ans = max(ans,T.get());
}
printf("%lld\n",ans);
} return ; }
【POJ 2482】 Stars in Your Windows的更多相关文章
- 【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
http://poj.org/problem?id=2482 线段树扫描线 #include<cstdio> #include<cstring> #include<alg ...
- 【POJ 2352】 Stars
[题目链接] http://poj.org/problem?id=2352 [算法] 树状数组 注意x坐标为0的情况 [代码] #include <algorithm> #include ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
随机推荐
- MySQL 5.6 Reference Manual-14.6 InnoDB Table Management
14.6 InnoDB Table Management 14.6.1 Creating InnoDB Tables 14.6.2 Moving or Copying InnoDB Tables to ...
- 使用JDK和axis2发布webservice
最近使用webservice进行远程调用一直很火,自从JDK1.6版本发布后,发布一个webservice项目变得更加简单了 笔者由于工作的需要针对JDK和axis2如何发布webservice做过相 ...
- mysql数据库索引原理及其常用引擎对比
索引原理 树数据结构及其算法简介 B+/-树: - 多路搜索树; - 时间复杂度O(logdN);h为节点出度,d为深度 红黑树: - 节点带有颜色的平衡二叉树 - 时间复杂度O(log2N);h节点 ...
- Java数组的运用
Java数组 应用1: 大乐透彩票模拟器: 规则: 前区01-35中随机生成5个号码 后区01-12中随机生成2个号码 模拟操作,系统自动生成号码组合,并且按从小到大的顺序输出结果 同时要求可以选择生 ...
- 关于如何成为高级java程序员
今日,对如何进一步提升java.成为一个高级的程序员有了兴趣,在网上看到一篇回答,感觉不错,记下来 总结了以下六点:一.JAVA基础 要想成为高级Java程序员,Java是一定要学习的.要成为高级程序 ...
- phpstudy不显示目录列表---设置方法
打开phpstudy,显示的项目文件路径不见了,其实是phpstudy的设置问题.以下是设置方法. 并将一下几个文件删除即可
- 00-- 关于C++ const 的全面总结
转:关于C++ const 的全面总结 C++中的const关键字的用法非常灵活,而使用const将大大改善程序的健壮性,本人根据各方面查到的资料进行总结如下,期望对朋友们有所帮助. Const 是C ...
- C# 遍历对象下的 属性
foreach (System.Reflection.PropertyInfo p in users.GetType().GetProperties()) { var xx = p.Name; var ...
- 关于pc端 app端pdf,word xls等文件预览的功能
第一种用H5标签<iframe>标签实现 返回的文件类型,文件流,文件流返回必须在设置 contentType对应的Mime Type, 返回文件的物理位置. 已经实测可以支持的文件类型 ...
- Jenkins 部署 PHP 应用
安装 Jenkins 方式一:docker方式安装 拉取jenkins官方镜像,按照镜像文档启动镜像就可以了 方式二:手动安装 以下所有操作都使用 root 用户进行操作. 在各项目官网,下载 Jav ...