Luogu1502 窗口的星星 (线段树扫描线)
将每个点拓展为矩形,将\(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 窗口的星星 (线段树扫描线)的更多相关文章
- 51nod 1208 窗上的星星 | 线段树 扫描线
51nod 1208 Stars In Your Window 题面 整点上有N颗星星,每颗星星有一个亮度.用一个平行于x轴和y轴,宽为W高为H的方框去套星星.套住的所有星星的亮度之和为S(包括边框上 ...
- 【学习笔记】线段树—扫描线补充 (IC_QQQ)
[学习笔记]线段树-扫描线补充 (IC_QQQ) (感谢 \(IC\)_\(QQQ\) 大佬授以本内容的著作权.此人超然于世外,仅有 \(Luogu\) 账号 尚可膜拜) [学习笔记]线段树详解(全) ...
- 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...
- BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...
- BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...
- hdu 5091(线段树+扫描线)
上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...
- POJ1151+线段树+扫描线
/* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...
随机推荐
- mongoDB 命令大全
每日一句 There should be a better way to start a day than waking up every morning. 应该有更好的方式开始新一天, 而不是千篇一 ...
- 用python解决打标签时将xml文件的标签名打错
用python解决打标签时将xml文件的标签名打错 问题描述:再进行达标签时将magnetic_tile的标签名错误的打成了magnetic_title,又不想一张一张的修改 出现问题的xml文件 & ...
- 关于『HTML5』第一弹
关于『HTML5』:第一弹 建议缩放90%食用 祝各位国庆节快乐!!1 经过了「过时的 HTML」.「正当时的 Markdown」的双重洗礼后,我下定决心,好好学习HTML5 这回不过时了吧(其实和 ...
- Go微服务框架go-kratos实战02:proto 代码生成和编码实现步骤
在上一篇 kratos quickstart 文章中,我们直接用 kratos new 命令生成了一个项目. 这一篇来看看 kratos API 的定义和使用. 一.kratos 中 API 简介 1 ...
- FFT 小记
写在前面 \(Q:\) 为什么会心血来潮去学 FFT \(A:\) 当本蒟蒻还在努力消化凸包时:.所以本蒟蒻也来看一下 等等 摸头警告 .思维已经废了 About FFT FFT( \(Fast\ F ...
- dotnet 在 linux 上构建问题(RID 的问题)
个人理解 一方面 /etc/os-release 中定义的的 ID VERSION_ID 是会与源代码中定义 RID 的相对应,如果不对应,就会报错 The specified RuntimeIden ...
- Vue回炉重造之三次封装axios
源码目录 在src目录下建立一个request文件夹.里面建立两个文件: http.js api.js 源码内容 http.js import axios from 'axios' // 引入axio ...
- DAST 黑盒漏洞扫描器 第五篇:漏洞扫描引擎与服务能力
0X01 前言 转载请标明来源:https://www.cnblogs.com/huim/ 本身需要对外有良好的服务能力,对内流程透明,有日志.问题排查简便. 这里的服务能力指的是系统层面的服务,将扫 ...
- Linux 源码编译安装软件
程序包编译安装的步骤: 源代码-->预处理-->编译-->汇编-->链接-->执行 多文件:文件中的代码之间,很可能存在跨文件依赖关系 1.编译源码的项目工具 使用相关的 ...
- bat-安装程序-切换路径的问题(小坑)
当批处理以管理员身份运行时,默认的cmd路径是 C:\Windows\system32 如果在批处理所在目录下存放了一些 安装程序,使用bat安装程序时,bat中去执行时 不会去当前目录去找 exe文 ...