【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 ...
随机推荐
- cuda中thread id
//////////////////////////////////////////////////////////////////////////// // // Copyright 1993-20 ...
- AppStore ipa (苹果内购)笔记
内购示意图 准备条件 苹果的开发者证书,已经为应用启用App内购,并在Xcode更新配置文件 itunes store设置 itunes中创建App及其它设置 参考:iOS应用程序内购/内付费(一) ...
- JavaScript作用域闭包简述
JavaScript作用域闭包简述 作用域 技术一般水平有限,有什么错的地方,望大家指正. 作用域就是变量起作用的范围.作用域包括全局作用域,函数作用域以块级作用域,ES6中的let和const可以形 ...
- java 22 - 16 多线程之生产者和消费者的问题
生产者和消费者问题的描述图 通过上图,我们可以发现: 生产者和消费者使用的都是同一个资源(肉包子) 所以,当使用线程的时候,这两类的锁也是同一把锁(为了避免出现线程安全问题) 例子:学生信息的录入和获 ...
- 深入了解Windows
1.1.什么是WindowMicrosoft Windows,是美国微软公司研发的一套操作系统,它问世于1985年,起初仅仅是Microsoft-DOS模拟环境,后续的系统版本由于微软不断的更新升级, ...
- request.getRequestDispather().forward()与response.sendRedirect()
request.getRequestDispather().forward(),是服务器端的跳转,地址栏无变化. response.sendRedirect()是客户端的跳转,地址栏发生变化.
- BZOJ 1854 【Scoi2010】 游戏
Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性 ...
- Castle.ActiveRecord 多对多关系 引发的错误处理
在Castle.ActiveRecord 实体类中,如果两个对象有 “多对多” 关系,一般的做法是将其分解为 两个“一对多”关系,但有时引发了 “您要删除 或 引用 的对象#2在数据库中不存在”的异常 ...
- Nodejs进阶:核心模块https 之 如何优雅的访问12306
本文摘录自<Nodejs学习笔记>,更多章节及更新,请访问 github主页地址.欢迎加群交流,群号 197339705. 模块概览 这个模块的重要性,基本不用强调了.在网络安全问题日益严 ...
- Web端PHP代码函数覆盖率测试解决方案
1. 关于代码覆盖率 衡量代码覆盖率有很多种层次,比如行覆盖率,函数/方法覆盖率,类覆盖率,分支覆盖率等等.代码覆盖率也是衡量测试质量的一个重要标准,对于黑盒测试来说,如果你不确定自己的测试用例是否真 ...