【题目链接】

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. Java中从控制台输入数据的几种常用方法(转转)

    原文博客地址:https://www.cnblogs.com/SzBlog/p/5404246.html 一.使用标准输入串System.in  //System.in.read()一次只读入一个字节 ...

  2. python3 常用模块详解

    这里是python3的一些常用模块的用法详解,大家可以在这里找到它们. Python3 循环语句 python中模块sys与os的一些常用方法 Python3字符串 详解 Python3之时间模块详述 ...

  3. 如何解决Android 5.0以上出现的警告:Service Intent must be expli

    有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent  must be explitict,也就是说从Lollip ...

  4. 命令行 RSA, Base64, Hash

    序 # -n 可以去掉换行符 echo -n '777777' RSA算法 加密 # 利用管道命令传递字符串加密 echo -n '777777' | openssl rsautl -encrypt ...

  5. C#模拟按键

    try { System.Threading.Thread.Sleep(); ; i < ; i++) { SendKeys.SendWait("{ENTER}"); Sen ...

  6. Vim 插件管理及安装

    1.先将ubuntu1204的软件源进行更新.sudo apt-get update 2.再在终端中敲如下命令,让程序自动安装,根据网速的好坏安装时间有长有短. wget -qO- https://r ...

  7. div与div之间的拖拽

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. 远程连接windows出现身份验证错误,提示"由于CredSSP加密Oracle修正"解决方案

    本机操作系统(OS版本:10.0.17134) 远程计算机操作系统(OS版本:6.3.9600) 远程连接的时候报错“出现身份验证错误,要求的函数不受支持.远程计算机:xxx 这可能是由于CredSS ...

  9. ToDoList(原生JS)了解一下

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. nyoj212-k尾相等数

    212-K尾相等数 内存限制:64MB时间限制:3000msSpecial Judge: No accepted:0submit:0 题目描述: 输入一个自然数K(K>1),如果存在自然数M和N ...