当前位置:网站首页>洛谷P4560 Wall 砖墙
洛谷P4560 Wall 砖墙
2022-08-11 04:00:00 【CLH_W】
题目背景
原题为交互试题,但在此请提交完整程序。
题目描述
给定一个长度为 nn且初始值全为 00的序列。你需要支持以下两种操作:
Add L, R, hL,R,h:将序列 [L, R][L,R]内所有值小于 hh的元素都赋为 hh,此时不改变高度大于 hh的元素值
Remove L, R, hL,R,h:将序列 [L, R][L,R]内所有值大于 hh的元素都赋为 hh,此时不改变高度小于 hh的元素值
你需要输出进行 kk次上述操作之后的序列。
输入格式
输入的第一行包含两个正整数 n, kn,k,分别表示序列中元素的个数以及操作数量,注意:序列下标编号为 00 ~ n-1n−1。
接下来 kk行每行包含 44个整数 t, L, R, ht,L,R,h,若 t = 1t=1则表明为 Add 操作,若 t = 2t=2则表明为 Remove 操作。 L, R, hL,R,h的含义见题目描述。
输出格式
输出包含 nn行,每行包含 11个整数。第 ii行的整数表示 kk次操作之后序列中编号为 i - 1i−1的元素的值。
输入输出样例
输入 #1复制
10 3
1 3 4 91220
1 5 9 48623
2 3 5 39412
输出 #1复制
0
0
0
39412
39412
39412
48623
48623
48623
48623
输入 #2复制
10 6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
输出 #2复制
3
4
5
4
3
3
0
0
1
0
说明/提示
子任务#1(8分):满足 1 \leq n \leq 10 000, 1 \leq k \leq 5 0001≤n≤10000,1≤k≤5000;
子任务#2(24分):满足 1 \leq n \leq 100 000, 1 \leq k \leq 500 0001≤n≤100000,1≤k≤500000,全部增加操作均在全部移除操作之前;
子任务#3(29分):满足 1 \leq n \leq 100 000, 1 \leq k \leq 500 0001≤n≤100000,1≤k≤500000;
子任务#4(39分):满足 1 \leq n \leq 2 000 000, 1 \leq k \leq 500 0001≤n≤2000000,1≤k≤500000。
所有操作的高度 hh满足 0 \leq h \leq 100 0000≤h≤100000。
上代码:
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 8e6 + 10, INF = 1e9 + 10;
template <typename A, typename B> inline bool chmin(A &a, B b){
if(a > b) {
a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){
if(a < b) {
a = b; return 1;} return 0;}
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, K, opt[MAXN], L[MAXN], R[MAXN], H[MAXN];
#define ls k << 1
#define rs k << 1 | 1
struct Node {
int l, r, mx, mn;
}T[MAXN];
void psmin(int k, int v) {
chmin(T[k].mx, v); chmin(T[k].mn, v);
}
void psmax(int k, int v) {
chmax(T[k].mx, v); chmax(T[k].mn, v);
}
void pushdown(int k) {
if(T[k].mn != INF) psmin(ls, T[k].mn), psmin(rs, T[k].mn), T[k].mn = INF;
if(T[k].mx != -INF) psmax(ls, T[k].mx), psmax(rs, T[k].mx), T[k].mx = -INF;
}
void Build(int k, int ll, int rr) {
T[k].l = ll; T[k].r = rr; T[k].mn = INF; T[k].mx = -INF;
if(ll == rr) return ;
int mid = ll + rr >> 1;
Build(ls, ll, mid);
Build(rs, mid + 1, rr);
}
void Int(int k, int ll, int rr, int v, int opt) {
if(ll <= T[k].l && T[k].r <= rr) {
opt == 2 ? psmin(k, v) : psmax(k, v);
return ;
}
pushdown(k);
int mid = T[k].l + T[k].r >> 1;
if(ll <= mid) Int(ls, ll, rr, v, opt);
if(rr > mid) Int(rs, ll, rr, v, opt);
}
void dfs(int k) {
if(T[k].l == T[k].r) {
printf("%d\n", max(0, min(T[k].mn, T[k].mx)));return ;}
pushdown(k);
dfs(ls); dfs(rs);
}
signed main() {
N = read(); K = read();
Build(1, 1, N);
for(int i = 1; i <= K; i++) {
int opt = read(), L = read() + 1, R = read() + 1, H = read();
if(opt == 1) Int(1, L, R, H, 1);
else Int(1, L, R, H, 2);//区间取min
}
dfs(1);
return 0;
}
边栏推荐
- LeetCode814 Math Question Day 15 Binary Tree Series Value "814 Binary Tree Pruning"
- Get the length of the linked list
- 洛谷P7441 Erinnerung
- Callable实现多线程
- 多串口RS485工业网关BL110
- Detailed explanation of VIT source code
- 【Yugong Series】August 2022 Go Teaching Course 036-Type Assertion
- Provincial level of Echart maps, as well as all prefecture-level download and use
- 华南师范宋宇老师课堂对话论文翻译
- App基本框架搭建丨日志管理 - KLog
猜你喜欢
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
LeetCode刷题第12天二叉树系列之《104 二叉树的最大深度》
【人话版】WEB3将至之“权益的游戏”
LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
Interchangeable Measurement Techniques - Geometric Errors
快速使用UE4制作”大场景游戏“
STC8H development (15): GPIO drive Ci24R1 wireless module
【FPGA】day22-SPI protocol loopback
The development of the massage chair control panel makes the massage chair simple and intelligent
WPF DataGrid 使用数据模板(2)
随机推荐
Which one to choose for mobile map development?
C# 一周入门高级编程之《C#-LINQ》Day Four
Uni - app - access to Chinese characters, pinyin initials (according to the Chinese get pinyin initials)
机器学习中什么是集成学习?
(转)JVM中那些区域会发生OOM?
机器学习怎么学?机器学习流程
洛谷P7441 Erinnerung
Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array
直播平台开发,Flutter,Drawer侧滑
云平台下ESB产品开发步骤说明
LeetCode刷题第16天之《239滑动窗口最大值》
获取Qt的安装信息:包括安装目录及各种宏地址
STC8H开发(十五): GPIO驱动Ci24R1无线模块
直播软件搭建,流式布局,支持单选、多选等
Is Redis old?Performance comparison between Redis and Dragonfly
Leetcode 669. 修剪二叉搜索树
Watch to monitor
Use jackson to parse json data in detail
Graphical LeetCode - 640. Solving Equations (Difficulty: Moderate)
【FPGA】day22-SPI protocol loopback