【题目链接】

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的更多相关文章

  1. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  2. 【POJ 2482】Stars in Your Window

    http://poj.org/problem?id=2482 线段树扫描线 #include<cstdio> #include<cstring> #include<alg ...

  3. 【POJ 2352】 Stars

    [题目链接] http://poj.org/problem?id=2352 [算法] 树状数组 注意x坐标为0的情况 [代码] #include <algorithm> #include ...

  4. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  5. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  6. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  7. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  8. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  9. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

随机推荐

  1. 大数据查询——HBase读写设计与实践--转

    背景介绍 本项目主要解决 check 和 opinion2 张历史数据表(历史数据是指当业务发生过程中的完整中间流程和结果数据)的在线查询.原实现基于 Oracle 提供存储查询服务,随着数据量的不断 ...

  2. Windows环境下使用强大的wget工具

    安装 下载[http://www.interlog.com/~tcharron/wgetwin.html] 解压到目录 比如我解压到D:\Tool\wget 添加wget环境变量,这样使用就更方便了, ...

  3. JqGrid saveRow方法报404错误

    TCX_1807工艺配置/检测项配置页面为jqgrid可编辑页面,使用的脚本为 ){ jQuery('#gridList').saveRow(lastId, true);//保存上一个修改的单元行 } ...

  4. JavaScript操作HTML&CSS简单入门

    - Java攻城狮学习路线 - 一. JavaScript基础 输出 使用 window.alert() 弹出警告框. 使用 document.write() 方法将内容写到 HTML 文档中. 使用 ...

  5. 使用纯 CSS 实现 Google Photos 照片列表布局

    文章太长,因为介绍了如何一步一步进化到最后接近完美的效果的,不想读的同学可以直接跳到最后一个大标题之后看代码.demo及原理就好,或者也可以直接看下面这个链接的源代码. 不过还是建议顺序读下去,因为后 ...

  6. css 中font属性知识点总结

    一. font属性值可以继承.例如子元素可以继承父元素的行高,字体大小等等. 二.font属性可以进行连写:font: font-sytle  font-weight  font-size/line- ...

  7. SQL Server将数据导出到SQL脚本文件

    http://www.studyofnet.com/news/list-8883.2-1-4.html 一.SQL Server 2008将数据导出到SQL脚本文件 1.打开SQL Server200 ...

  8. **PCD数据获取:Kinect+OpenNI+PCL对接(代码)

    前言: PCL使用点云作为数据格式,Kinect可以直接作为三维图像的数据源产生三维数据,其中的桥梁是OpenNI和PrimeSense.为了方便地使用Kinect的数据,还是把OpenNI获取的基础 ...

  9. C++基础 (5) 第五天 重载new delete () 只能操作符 自定义string类

    1 昨日回顾 1.static 对整个类共享 可以直接用 类::方法 调用 如果是私有的 可以提供一个静态的访问静态成员的方法 2 自定义的数组类-重载操作符[] 3 重载new和delete 4 重 ...

  10. vue中数组变动更新检测

    Vue 包含两种观察数组的方法分别如下 1.变异方法 顾名思义,变异方法会改变被这些方法调用的原始数组,它们也将会触发视图更新,这些方法如下 push() pop() shift() unshift( ...