【POJ 2482】Stars in Your Window
http://poj.org/problem?id=2482
线段树扫描线
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 20003;
int in() {
int k = 0, fh = 1; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = (k << 3) + (k << 1) + c - '0';
return k * fh;
} namespace SegmentTree {
int ma[N << 2], lazy[N << 2], L, R, c, top;
void init(int num) {
top = num;
}
void pushdown(int rt, int l, int r) {
if (lazy[rt]) {
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
ma[rt << 1] += lazy[rt];
ma[rt << 1 | 1] += lazy[rt];
lazy[rt] = 0;
}
}
void pushup(int rt) {
ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]);
}
void update(int rt, int l, int r) {
if (L <= l && r <= R) {
ma[rt] += c;
lazy[rt] += c; return;
}
int mid = (l + r) >> 1;
pushdown(rt, l, r);
if (L <= mid) update(rt << 1, l, mid);
if (R > mid) update(rt << 1 | 1, mid + 1 ,r);
pushup(rt);
}
void cover(int l, int r, int num) {
L = l; R = r; c = num;
update(1, 1, top);
}
int query() {
return ma[1];
}
} int n, w, h, H[10003], dis[10003], cnt, down[10003];
struct node {
int x, y, z;
bool operator < (const node &A) const {
return x < A.x;
}
} S[10003]; int main() {
while (~scanf("%d%d%d", &n, &w, &h)) {
cnt = 0;
for(int i = 1; i <= n; ++i) {
S[i].x = in(); S[i].y = in(); S[i].z = in();
H[++cnt] = S[i].y;
}
sort(H + 1, H + cnt + 1);
cnt = unique(H + 1, H + cnt + 1) - H;
for(int i = 1; i <= n; ++i)
S[i].y = lower_bound(H + 1, H + cnt, S[i].y) - H;
sort(S + 1, S + n + 1);
int head = cnt - 1, tail = 1;
for(int i = cnt - 1; i >= 1; --i) {
while (head >= 1 && H[i] - H[head] < h) --head;
down[i] = head + 1;
} SegmentTree::init(cnt - 1); head = 1; tail = 1;
while (tail <= n && S[tail].x - S[1].x < w) {
SegmentTree::cover(down[S[tail].y], S[tail].y, S[tail].z);
++tail;
}
int ans = SegmentTree::query();
while (head <= n) {
SegmentTree::cover(down[S[head].y], S[head].y, -S[head].z);
++head;
while (head <= n && S[head].x == S[head - 1].x) {
SegmentTree::cover(down[S[head].y], S[head].y, -S[head].z);
++head;
}
while (tail <= n && S[tail].x - S[head].x < w) {
SegmentTree::cover(down[S[tail].y], S[tail].y, S[tail].z);
++tail;
}
ans = max(ans, SegmentTree::query());
}
printf("%d\n", ans);
} return 0;
}
【POJ 2482】Stars in Your Window的更多相关文章
- 【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 Windows
[题目链接] http://poj.org/problem?id=2482 [算法] 线段树 + 扫描线 [代码] #include <algorithm> #include <bi ...
- 【POJ2482】【线段树】Stars in Your Window
Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw ...
- 【POJ 2352】 Stars
[题目链接] http://poj.org/problem?id=2352 [算法] 树状数组 注意x坐标为0的情况 [代码] #include <algorithm> #include ...
- 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 (扫描线 )
题意:二维平面上给你N颗星,给出星星的坐标,亮度: 然后给你一个W*H的窗口,问你最大的亮度和. 思路:扫描线,假设有一个inf*H的窗口,按照y排序,那么就把H范围内的星星放入了这个窗口(单调队列实 ...
- 【POJ2482】Stars in Your Window
[POJ2482]Stars in Your Window 题面 vjudge 题解 第一眼还真没发现这题居然™是个扫描线 令点的坐标为\((x,y)\)权值为\(c\),则 若这个点能对结果有\(c ...
- 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 ...
随机推荐
- 北理工c语言期末考试
1 给定一个区间,输出其中前半部分数字之和等于后半部分数字之和的数,没有则输出No output.(15分) 题目内容: 给定一个区间,输出其中前半部分数字之和等于后半部分数字之和的数,没有则输出No ...
- IIS7.5中神秘的ApplicationPoolIdentity
IIS7.5中(仅win7,win2008 SP2,win2008 R2支持),应用程序池的运行帐号,除了指定为LocalService,LocalSystem,NetWorkService这三种基本 ...
- VS的快捷键F12改成和ECLIPSE一样用ctrl+点击下载线
安装resharper 插件即可 不过这个插件是收费的,可免费体验30天
- [No000039]操作系统Operating Systems用户级线程User Threads
多进程是操作系统的基本图像 是否可以资源不动而切换指令序列? 进程 = 资源 + 指令执行序列 线程: 保留了并发的优点,避免了进程切换代价 实质就是映射表不变而PC 指针变 多个执行序列+ 一个地址 ...
- Android中实现如下多语言选择Radiobutton效果
手边的samsung手机设置多语言的方式一般是点击设置多语言的一栏后进入到多语言选择界面,选择完成之后当前的语言环境用小字方式直接显示在设置多语言栏的下方.另一种选择多语言的方式如上图所示,我也在系统 ...
- iOS中NSScanner 的用法
NSScanner是一个类,用于在字符串中扫描指定的字符,尤其是把它们翻译/转换为数字和别的字符串.可以创建NSScanner时制定他的String属性,然后scanner会按照你的要求从头到尾扫描这 ...
- 安装ESXi5.5遇到Relocating modules and starting up the kernel的处理
在一些Dell较旧的服务器上安装ESXi 5.x时, 会遇到卡在Relocating modules and starting up the kernel过不去的问题. 比如我装的这台CS24VSS. ...
- ESXi 5.5 命令行克隆虚拟机
1. 开启ESXi的SSH功能,用vSphere Client登录ESXi, 选中服务器, 在右侧标签栏选择Configuration->SecurityProfile->Services ...
- 探索Windows 8.1 Update 新功能点
Windows 8.1 Update 已经使用一段时间了,整体感觉比Windows 8.1 方便了不少,尤其是对鼠标用户来说更是进行了很多优化. 应用磁贴尺寸 在应用磁贴点击鼠标右键,有小.中.宽.大 ...
- [转]SpringMVC使用@ResponseBody时返回json的日期格式、@DatetimeFormat使用注意
一.SpringMVC使用@ResponseBody时返回json的日期格式 前提了解: @ResponseBody 返回json字符串的核心类是org.springframework.http.co ...