HDU 4391 Paint The Wall 段树(水

HDU 4391 Paint The Wall 段树(水

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

意甲冠军:

特定n多头排列。m操作

以下是各点的颜色

以下m一种操纵:

1 l r col 染色

2 l r col 问间隔col色点

== 通的操作+区间内最大最小颜色数的优化,感觉非常不科学。。。

==感觉能够卡掉这样的写法。。反正就是不科学嘛 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define L(x) tree[x].l
#define R(x) tree[x].r
#define Len(x) tree[x].len
#define Lazy(x) tree[x].lazy
#define M(x) tree[x].minn
#define W(x) tree[x].maxx
#define Lson(x) (x<<1)
#define Rson(x) (x<<1|1)
const int N = 100010;
struct node{
	int l, r, len, lazy, minn, maxx;
}tree[N<<2];
int col[N];
void push_up(int id){
	if(Lazy(Lson(id)) == Lazy(Rson(id)))
		Lazy(id) = Lazy(Lson(id));
	else Lazy(id) = -1;
	M(id) = min(M(Lson(id)), M(Rson(id)));
	W(id) = max(W(Lson(id)), W(Rson(id)));
}
void push_down(int id){
	if(Lazy(id) != -1){
		Lazy(Lson(id)) = Lazy(Rson(id)) = Lazy(id);
		M(Lson(id)) = W(Lson(id)) = Lazy(id);
		M(Rson(id)) = W(Rson(id)) = Lazy(id);
	}
}
void build(int l, int r, int id){
	L(id) = l; R(id) = r;
	Len(id) = r-l+1;
	Lazy(id) = -1;
	if(l == r){
		Lazy(id) = col[l];
		W(id) = M(id) = col[l];
		return ;
	}
	int mid = (l+r)>>1;
	build(l, mid, Lson(id));
	build(mid+1, r, Rson(id));
	push_up(id);
}
void updata(int l, int r,int val, int id){
	if(l == L(id) && R(id) == r){
		Lazy(id) = val;
		W(id) = M(id) = val;
		return ;
	}
	push_down(id);
	int mid = (L(id) + R(id)) >>1;
	if(mid < l)
		updata(l, r, val, Rson(id));
	else if(r <= mid)
		updata(l, r, val, Lson(id));
	else {
		updata(l, mid, val, Lson(id));
		updata(mid+1, r, val, Rson(id));
	}
	push_up(id);
}
int query(int l, int r, int col, int id){
	if(!(M(id)<=col && col<=W(id))) return 0;
	if(Lazy(id)!=-1){
		if(Lazy(id) == col)
			return r-l+1;
		else return 0;
	}
	push_down(id);
	int mid = (L(id) + R(id)) >>1;
	if(mid < l)
		return query(l, r, col, Rson(id));
	else if(r <= mid)
		return query(l, r, col, Lson(id));
	else
		return query(l, mid, col, Lson(id)) + query(mid+1, r, col, Rson(id));
}
int n, que;

int main() {
	while (cin>>n>>que) {
		for(int i = 1; i <= n; i++)scanf("%d", &col[i]);
		build(1, n, 1);
		while(que--){
			int type, l, r, color;
			scanf("%d %d %d %d", &type, &l, &r, &color);
			l++; r++;
			if(type == 1)
				updata(l, r, color, 1);
			else
				printf("%d\n", query(l, r, color, 1));

		}
	}
	return 0;
}
/*
5 12
1 2 3 4 0
2 1 3 3
1 1 3 1
2 1 3 3
2 0 3 1
2 3 4 1
1 0 4 0
2 0 4 0
2 0 4 2000000000
1 0 0 1
1 4 4 2
2 0 4 1
2 0 4 2

*/

版权声明:本文博客原创文章。博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117563.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Linux系统的内核态和用户态[通俗易懂]

    Linux系统的内核态和用户态[通俗易懂]一、 Unix/Linux的体系架构  如上图所示,从宏观上来看,Linux操作系统的体系架构分为用户态和内核态(或者用户空间和内核)。内核从本质上看是一种软件——控制计算机的硬件资源,并提供上层应用程序运行的环境。用户态即上层应用程序的活动空间,应用程序的执行必须依托于内核提供的资源,包括CPU资源、存储资源、I/O资源等。为了使上层应用能够访问到这些资源,内核必须为上层应用提供

    2025年12月13日
    2
  • 数据仓库中如何使用索引

    数据仓库中如何使用索引

    2021年11月26日
    61
  • react路由权限设置

    react路由权限设置说明在react项目中有时我们的一些页面需要权限才能访问,这里以需要登录才能访问进行的设置在这里可以看到权限页面和关于页面是需要登录才能访问的importReact,{Component,useState,useEffect,useRef}from’react’;import{HashRouterasRouter,Route,NavLink,Redirect,Switch,useHistory}from”react-router-dom”;classAPP

    2022年5月6日
    177
  • pytest的assert_Python断言

    pytest的assert_Python断言前言断言是写自动化测试基本最重要的一步,一个用例没有断言,就失去了自动化测试的意义了。什么是断言呢?简单来讲就是实际结果和期望结果去对比,符合预期那就测试pass,不符合预期那就测试failed

    2022年7月31日
    8
  • git显示当前分支改动的文件「建议收藏」

    git显示当前分支改动的文件「建议收藏」一个命令显示当前分支与父分支的差异文件。gitcheckoutbranch1gitdiff–name-statusparent_branch1

    2022年8月22日
    29
  • Django(76)isort工具对import导入进行排序

    Django(76)isort工具对import导入进行排序前言我们在开发项目时经常会进行导包有import*格式的,还有from*import*格式的,最后就会显示的很乱,那么有没有什么工具能对导包进行一键排序呢?答案是有的,使用isort工具i

    2022年7月30日
    11

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号