【题目链接】

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. A - A Compatible Pair

    Problem description Nian is a monster which lives deep in the oceans. Once a year, it shows up on th ...

  2. 8) 十分钟学会android--Activity的生命周期之停止与重启

    恰当的停止与重启我们的activity是很重要的,在activity生命周期中,他们能确保用户感知到程序的存在并不会丢失他们的进度.在下面一些关键的场景中会涉及到停止与重启: 用户打开最近使用app的 ...

  3. Windows各种计时器

    (一):OnTimer类 1.打开对应对话框的类向导ClassWizard. 2.在消息映射MessageMaps中添加消息Message:WM_TIMER. 3.程序代码中将自动添加函数OnTime ...

  4. 03--实例讲解虚拟机3种网络模式(桥接、nat、Host-only)

    前言 很多人安装虚拟机的时候,经常遇到不能上网的问题,而vmware有三种网络模式,对初学者来说也比较眼花聊乱,今天我就来基于虚拟机3种网络模式,帮大家普及下虚拟机上网的背景知识.(博文原创自http ...

  5. HTML 单击a标签 实现下载文件而不是浏览器打开预览

    <a d ownload class="down" title="">

  6. webstorm主题网址

    http://www.phpstorm-themes.com/ http://www.riaway.com/theme.php

  7. openlayers5学习笔记-001

    tmp.initPoint = function (items) { //初始化所有农户点坐标,聚合 var count = items.length; var features = new Arra ...

  8. codeforces 468B two set(并查集)

    链接 B. Two Sets 题意 给两个集合A B,两个数a b,n个数x,分配n个数到两个集合,要求x , a-x在同一个集合,x , b-x在同一个集合,属于A集合的数输出0,B的输出1,无解输 ...

  9. centos 6.10 永久修改主机名

    1> 修改配置文件 vim /etc/sysconfig/network #HOSTNAME=localhost.localdomain HOSTNAME=tomcat   2> 修改ho ...

  10. Windows Server菜鸟宝典之一:Windows Server 2008 R2 AD服务器搭建

        1.对于将要安装成为DC的服务器来讲,其系统配置以及基本的磁盘规划在此就不在累述了,但是关键的网络连接属性是必须要注意的.可以通过打开本地连接的属性来进行配置其IP属性.作为服务器DC的IP地 ...