将每个点拓展为矩形,将\(y\)离散,延\(x\)轴扫描,每次更新最值

用了一百年的pushdown操作疑似有问题,亦或这道题特殊,我乱改了pushdown位置就过了,我能怎么办,WA了一发,y数组没开够又RE了一发。。。

话说POJ上的情书让我回忆起童年那个彪悍的女孩,一晃十年了

  Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I still remember, vividly, on the beautiful Zhuhai Campus, 4 years ago, from the moment I saw you smile, as you were walking out of the classroom and turned your head back, with the soft sunset glow shining on your rosy cheek, I knew, I knew that I was already drunk on you. Then, after several months’ observation and prying, your grace and your wisdom, your attitude to life and your aspiration for future were all strongly impressed on my memory. You were the glamorous and sunny girl whom I always dream of to share the rest of my life with. Alas, actually you were far beyond my wildest dreams and I had no idea about how to bridge that gulf between you and me. So I schemed nothing but to wait, to wait for an appropriate opportunity. Till now — the arrival of graduation, I realize I am such an idiot that one should create the opportunity and seize it instead of just waiting.

  These days, having parted with friends, roommates and classmates one after another, I still cannot believe the fact that after waving hands, these familiar faces will soon vanish from our life and become no more than a memory. I will move out from school tomorrow. And you are planning to fly far far away, to pursue your future and fulfill your dreams. Perhaps we will not meet each other any more if without fate and luck. So tonight, I was wandering around your dormitory building hoping to meet you there by chance. But contradictorily, your appearance must quicken my heartbeat and my clumsy tongue might be not able to belch out a word. I cannot remember how many times I have passed your dormitory building both in Zhuhai and Guangzhou, and each time aspired to see you appear in the balcony or your silhouette that cast on the window. I cannot remember how many times this idea comes to my mind: call her out to have dinner or at least a conversation. But each time, thinking of your excellence and my commonness, the predominance of timidity over courage drove me leave silently.

  Graduation, means the end of life in university, the end of these glorious, romantic years. Your lovely smile which is my original incentive to work hard and this unrequited love will be both sealed as a memory in the deep of my heart and my mind. Graduation, also means a start of new life, a footprint on the way to bright prospect. I truly hope you will be happy everyday abroad and everything goes well. Meanwhile, I will try to get out from puerility and become more sophisticated. To pursue my own love and happiness here in reality will be my ideal I never desert.

  Farewell, my princess!

  If someday, somewhere, we have a chance to gather, even as gray-haired man and woman, at that time, I hope we can be good friends to share this memory proudly to relight the youthful and joyful emotions. If this chance never comes, I wish I were the stars in the sky and twinkling in your window, to bless you far away, as friends, to accompany you every night, sharing the sweet dreams or going through the nightmares together.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long //#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r const int N = 10007; struct Line{
int X, Y1, Y2, w;
bool operator < (const Line &com) const{
if(X != com.X) return X < com.X;
return w > com.w;
}
}a[N << 1];
struct Tree{
int mx, tag;
}t[N << 3]; inline void Pushup(int rt){
t[rt].mx = Max(t[rt << 1].mx, t[rt << 1 | 1].mx);
}
inline void Pushdown(int rt, int l, int r){
if(!t[rt].tag) return;
t[rt].mx += t[rt].tag;
if(l != r){
t[rt << 1].tag += t[rt].tag;
t[rt << 1 | 1].tag += t[rt].tag;
}
t[rt].tag = 0;
}
inline void Updata(int rt, int l, int r, int L, int R, int w){
if(L <= l && r <= R){
t[rt].tag += w;
// Pushdown(rt, l, r);
return;
}
// Pushdown(rt, l, r);
int mid = (l + r) >> 1;
if(L <= mid) Updata(lson, L, R, w);
if(R > mid) Updata(rson, L, R, w); Pushdown(lson), Pushdown(rson); // QAQ Pushup(rt);
} int y[N << 1];
int main(){
int Tasks;
io >> Tasks;
while(Tasks--){
Fill(t, 0);
int n, W, H;
io >> n >> W >> H;
R(i,1,n){
int X, Y, val;
io >> X >> Y >> val;
a[i] = (Line){X, Y, Y + H - 1, val};
a[i + n] = (Line){X + W - 1, Y, Y + H - 1, -val};
y[i] = Y;
y[i + n] = Y + H - 1;
} n <<= 1;
sort(a + 1, a + n + 1);
sort(y + 1, y + n + 1);
int m = unique(y + 1, y + n + 1) - y - 1; int ans = 0;
R(i,1,n){
int l = lower_bound(y + 1, y + m + 1, a[i].Y1) - y;
int r = lower_bound(y + 1, y + m + 1, a[i].Y2) - y;
Updata(1, 1, m, l, r, a[i].w);
ans = Max(ans, t[1].mx);
} printf("%d\n", ans);
} return 0;
}


破案了,我pushdown傻逼了, 一中午愉悦的聊天后 终于圆满了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long //#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r const int N = 10007; struct Line{
int X, Y1, Y2, w;
bool operator < (const Line &com) const{
if(X != com.X) return X < com.X;
return w > com.w;
}
}a[N << 1];
struct Tree{
int mx, tag;
}t[N << 3]; inline void Pushup(int rt){
t[rt].mx = Max(t[rt << 1].mx, t[rt << 1 | 1].mx);
}
inline void Pushdown(int rt, int l, int r){
if(!t[rt].tag) return;
t[rt << 1].mx += t[rt].tag;
t[rt << 1 | 1].mx += t[rt].tag;
t[rt << 1].tag += t[rt].tag;
t[rt << 1 | 1].tag += t[rt].tag;
t[rt].tag = 0;
}
inline void Updata(int rt, int l, int r, int L, int R, int w){
if(L <= l && r <= R){
t[rt].mx += w;
t[rt].tag += w;
return;
}
Pushdown(rt, l, r);
int mid = (l + r) >> 1;
if(L <= mid) Updata(lson, L, R, w);
if(R > mid) Updata(rson, L, R, w);
Pushup(rt);
} int y[N << 1];
int main(){
FileOpen();
int Tasks;
io >> Tasks;
while(Tasks--){
Fill(t, 0);
int n, W, H;
io >> n >> W >> H;
R(i,1,n){
int X, Y, val;
io >> X >> Y >> val;
a[i] = (Line){X, Y, Y + H - 1, val};
a[i + n] = (Line){X + W - 1, Y, Y + H - 1, -val};
y[i] = Y;
y[i + n] = Y + H - 1;
} n <<= 1;
sort(a + 1, a + n + 1);
sort(y + 1, y + n + 1);
int m = unique(y + 1, y + n + 1) - y - 1; int ans = 0;
R(i,1,n){
int l = lower_bound(y + 1, y + m + 1, a[i].Y1) - y;
int r = lower_bound(y + 1, y + m + 1, a[i].Y2) - y;
Updata(1, 1, m, l, r, a[i].w);
ans = Max(ans, t[1].mx);
} printf("%d\n", ans);
} return 0;
}

Luogu1502 窗口的星星 (线段树扫描线)的更多相关文章

  1. 51nod 1208 窗上的星星 | 线段树 扫描线

    51nod 1208 Stars In Your Window 题面 整点上有N颗星星,每颗星星有一个亮度.用一个平行于x轴和y轴,宽为W高为H的方框去套星星.套住的所有星星的亮度之和为S(包括边框上 ...

  2. 【学习笔记】线段树—扫描线补充 (IC_QQQ)

    [学习笔记]线段树-扫描线补充 (IC_QQQ) (感谢 \(IC\)_\(QQQ\) 大佬授以本内容的著作权.此人超然于世外,仅有 \(Luogu\) 账号 尚可膜拜) [学习笔记]线段树详解(全) ...

  3. 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)

    D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  4. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  5. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  6. HDU 4419 Colourful Rectangle --离散化+线段树扫描线

    题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...

  7. BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤

    3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...

  8. BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞

    看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...

  9. hdu 5091(线段树+扫描线)

    上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...

  10. POJ1151+线段树+扫描线

    /* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...

随机推荐

  1. Fast-Rcnn学习笔记

    Fast-Rcnn学习笔记 paper code Fast-RCNN总览 step1:图片先放进卷积层 step2:再卷积层的特征图谱上回映射出对应的感兴趣区域 step3:集过一层ROI Pooli ...

  2. Navicat破解激活流程

    ​​ ​ Navicat Navicat Premium 是一套数据库开发工具,让你从单一应用程序中同时连接 MySQL.MariaDB.MongoDB.SQL Server.Oracle.Postg ...

  3. 一次生产环境的docker MySQL故障

    问题 昨天下午本来要去吃下午茶,然后前端小伙伴突然说接口怎么崩了,我登上sentry一看,报错了 (2005, "Unknown MySQL server host 'mysql' (-3) ...

  4. Linux免密登陆配置(互信配置)

    Linux免密登陆配置(互信配置) 1.生成当前用户的秘钥文件 [oracle@localhost .ssh]$ ssh-keygen -t rsa 2.配置远程登录用户的公钥文件 将公钥文件拷贝至另 ...

  5. Camunda BPM的总体架构介绍

    前言    Camunda是一个基于Java的框架,支持用于工作流和流程自动化的BPMN.用于案例管理的CMMN和用于业务决策管理的DMN.   本篇文章我们仅考虑BPMN流程引擎,先不涉及CMMN和 ...

  6. C#实现[移除文件名中的非中文字符]

    更新记录: 2022年5月28日 从程序中抽出方法复用. 处理财务文件时写的一个小函数.用于移除文件名中的非中文字符. /// <summary> /// 移除文件名中的非中文字符 /// ...

  7. Quartus II 13.0 sp1的官方下载页面

    今天为了下个ModelSim跑到网上去找下载资源,清一色的百度网盘,下载速度60k/s,简直有病,于是跑到Intel官网上把连接挖出来了,供各位直接下载 实测使用IDM多线程下载速度可以轻松上到数MB ...

  8. mysql5.7安装要踩的坑

    因为官网下载的是绿色版,所以要做一些配置 1.在mysql根目录新增data文件夹和my.ini文件 my.ini文件内容 [mysql]# 设置mysql客户端默认字符集default-charac ...

  9. SAP OOALV 添加状态灯

    *&---------------------------------------------------------------------* INCLUDE <icon>. T ...

  10. 记一次 .NET 某物管后台服务 卡死分析

    一:背景 1. 讲故事 这几个月经常被朋友问,为什么不更新这个系列了,哈哈,确实停了好久,主要还是打基础去了,分析 dump 的能力不在于会灵活使用 windbg,而是对底层知识有一个深厚的理解,比如 ...