【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 ...
随机推荐
- MSDN性能分析相关网站收集
Visual Studio 性能分析初学者指南 | Microsoft Docshttps://docs.microsoft.com/zh-cn/visualstudio/profiling/begi ...
- highcharts例子
直接看代码 <script language="JavaScript"> $(document).ready(function() { $.ajax({ type:'p ...
- oc的属性
Declared property A declared property provides a syntactical shorthand for declaring a class’s acces ...
- python的小数据池和深浅拷贝
小数据池 一种数据缓存机制,也称驻留机制 在同一代码块,相同的值不会开辟新的内存 特殊字符除外 小数据池只针对:在控制台时! 数字 :-5到256间的整数会被缓存 布尔值:都会缓存8 字符串 小于等于 ...
- JS 用+1、-1填12()34()56()78()9=59
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- eclipse中的maven项目部署到tomcat中
http://www.cnblogs.com/guodefu909/p/4874549.html
- MyBatis源码分析(各组件关系+底层原理
MyBatis源码分析MyBatis流程图 下面将结合代码具体分析. MyBatis具体代码分析 SqlSessionFactoryBuilder根据XML文件流,或者Configuration类实例 ...
- OpenVAS虚拟机安装
官方网站:http://www.openvas.org/ 参考链接:http://www.openvas.org/vm.html 下载地址:http://dl.greenbone.net/downlo ...
- C++基础 (8) 第八天 数组指针 模板指针 C语言中的多态 模板函数
1昨日回顾 2 多态的练习-圆的图形 3多态的练习-程序员薪资 4员工管理案例-抽象类和技术员工的实现 employee.h: employee.cpp: technician.h: technici ...
- IDEA热部署配置
一.IDEA热加载的作用: 热加载的作用就是当你保存修改,新增,删除代码或者文件后,不需要重新启动项目,直接就能运行. 二.IDEA热记载的配置方法 1.配置pom文件,加载依赖 Maven. < ...