当前位置:网站首页>洛谷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;
}
边栏推荐
- uni-app - city selection index list / city list sorted by A-Z (uview component library IndexList index list)
- Map中的getOrDefualt方法
- STC8H开发(十五): GPIO驱动Ci24R1无线模块
- LeetCode刷题第11天字符串系列之《 58最后一个单词长度》
- 每日一题-滑动窗口
- Design and Realization of Employment Management System in Colleges and Universities
- 《卫星界》刊评“星辰大海”计划:孙宇晨为太空旅游带来新的机遇
- 直播平台开发,Flutter,Drawer侧滑
- "3 Longest Substring Without Repeating Characters" on the 17th day of LeetCode brushing
- What is third-party payment?
猜你喜欢

Get Qt installation information: including installation directory and various macro addresses

Build Zabbix Kubernetes cluster monitoring platform

Getting Started with Raspberry Pi (5) System Backup
![[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface](/img/cb/41e5f553b0b776dccf0e39f9bf377f.png)
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface

A large horse carries 2 stone of grain, a middle horse carries 1 stone of grain, and two ponies carry one stone of grain. It takes 100 horses to carry 100 stone of grain. How to distribute it?

Clang Code Model: Error: The clangbackend executable “X:/clangbackend.exe“ could not be started

一文读懂 高性能可预期数据中心网络
![[FPGA] day19- binary to decimal (BCD code)](/img/d8/6d223e5e81786335a143f135385b08.png)
[FPGA] day19- binary to decimal (BCD code)
![[FPGA] Design Ideas - I2C Protocol](/img/ad/7bd52222e81b81a02b72cd3fbc5e16.png)
[FPGA] Design Ideas - I2C Protocol

【FPGA】day19-二进制转换为十进制(BCD码)
随机推荐
“顶梁柱”滑坡、新增长极难担重任,阿里“蹲下”是为了跳更高?
A brief analysis of whether programmatic futures trading or manual order is better?
【FPGA】day19-二进制转换为十进制(BCD码)
How to rebuild after pathman_config and pathman_config_params are deleted?
Where can machine learning be applied?What is machine learning useful for?
rub the heat - do not open
【FPGA】day18-ds18b20实现温度采集
Getting Started with Raspberry Pi (5) System Backup
UNI-APP_iphone bottom safe area
Detailed explanation of VIT source code
【FPGA】day22-SPI protocol loopback
Differences and connections between distributed and clustered
Graphical LeetCode - 640. Solving Equations (Difficulty: Moderate)
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
uni-app - city selection index list / city list sorted by A-Z (uview component library IndexList index list)
【ADI低功耗2k代码】基于ADuCM4050的ADXL363、TMP75的加速度、温度检测及串口打印、蜂鸣器播放音乐(孤勇者)
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
A large horse carries 2 stone of grain, a middle horse carries 1 stone of grain, and two ponies carry one stone of grain. It takes 100 horses to carry 100 stone of grain. How to distribute it?
shell监视gpu使用情况
Alibaba Cloud releases 3 high-performance computing solutions