hdu-5023线段树刷题
title: hdu-5023线段树刷题
date: 2018-10-18 13:32:13
tags:
- acm
- 刷题
categories: - ACM-线段树
概述
这道题和上次做的那道染色问题一样,,,这次主要是看看我再过去两三天之后,,大概凭借以前的记忆敲出来得多长的时间,,,,
结果是,,,大体的框架没问题了,,,,一遍下来编译也没问题,,,但是,,细节问题有两个,,,
- 数组写成了1e6而不是1e6+10虽然对本题没什么影响,,
- 建树中的初始化操作时染色初始化为2,,,所以应该是从右往左数的第二个bit记为1,,,然后我就少算了一位,,,因为bitset可以看作是一个从右向左并且从0开始的数组,,所以是col[1] = 1,,,这样wa了一发
- 最后一个,,,,输出格式错误,,,,噗噗噗噗
代码
思路与poj那一道一模一样,,直接扔代码
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <bitset>
using namespace std;
const int maxn = 1e6 + 10;
struct node
{
int l;
int r;
int laz;
bitset<30> col;
}node[maxn << 2];
#define aaa cout << node[rt].col << endl;
void build(int rt , int l , int r)
{
node[rt].l = l;
node[rt].r = r;
node[rt].laz = 0;
node[rt].col = 0;
if(node[rt].l == node[rt].r)
{
bitset<30> t;
t.set(1);
node[rt].col = t;
return;
}
int mid = (node[rt].l + node[rt].r) >> 1;
build(rt << 1 , l , mid);
build(rt << 1 | 1 , mid + 1 , r);
node[rt].col = node[rt << 1].col | node[rt << 1 | 1].col;
return;
}
void pushdown(int rt)
{
if(node[rt].laz)
{
node[rt << 1].col = node[rt].col;
node[rt << 1 | 1].col = node[rt].col;
node[rt << 1].laz = node[rt].laz;
node[rt << 1 | 1].laz = node[rt].laz;
node[rt].laz = 0;
}
}
void update(int rt , int L , int R , int C)
{
if(L <= node[rt].l && node[rt].r <= R)
{
bitset<30> t;
t.set(C - 1);
node[rt].col = t;
node[rt].laz = C;
return;
}
pushdown(rt);
int mid = (node[rt].l + node[rt].r) >> 1;
if(L <= mid) update(rt << 1 , L , R , C);
if(R > mid) update(rt << 1 | 1 , L , R , C);
node[rt].col = node[rt << 1].col | node[rt << 1 | 1].col;
return;
}
bitset<30> query(int rt , int L , int R)
{
if(L <= node[rt].l && node[rt].r <= R)
{
return node[rt].col;
}
pushdown(rt);
bitset<30> ans(0);
int mid = (node[rt].l + node[rt].r) >> 1;
if(L <= mid) ans |= query(rt << 1 , L , R);
if(R > mid) ans |= query(rt << 1 | 1 , L , R);
return ans;
}
int main()
{
int n , m;
while(scanf("%d%d" , &n , &m) && n && m)
{
build(1 , 1 , n);
while(m--)
{
char c;
scanf(" %c" , &c);
if(c == 'P')
{
int l , r , v;
scanf("%d%d%d" , &l , &r , &v);
update(1 , l , r , v);
}
else
{
int l , r;
scanf("%d%d" , &l , &r);
bitset<30> ans = query(1 , l , r);
bool flag = true;
for(int i = 1; i <= 30; ++i , ans>>=1)
if(ans[0] == 1)
if(flag)
printf("%d" , i) , flag = false;
else
printf(" %d" , i);
printf("\n");
}
}
}
}
先水一题,,,下午继续QAQ
(end)
hdu-5023线段树刷题的更多相关文章
- hdu-1540线段树刷题
title: hdu-1540线段树刷题 date: 2018-10-18 19:55:21 tags: acm 刷题 categories: ACM-线段树 概述 哇,,,这道线段树的题可以说是到目 ...
- poj-2777线段树刷题
title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...
- zoj-1610线段树刷题
title: zoj-1610线段树刷题 date: 2018-10-16 16:49:47 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道简单的线段树区间染色问 ...
- hdu 5023 线段树+状压
http://acm.hdu.edu.cn/showproblem.php?pid=5023 在片段上着色,有两种操作,如下: 第一种:P a b c 把 a 片段至 b 片段的颜色都变为 c . 第 ...
- HDU 5023线段树区间染色,统计区间内颜色个数
这个也是一个线段树的模板 #include<iostream> #include<string.h> #include<algorithm> #include< ...
- hdu 5023 线段树+位运算
主要考线段树的区间修改和区间查询,这里有一个问题就是这么把一个区间的多种颜色上传给父亲甚至祖先节点,在这里题目告诉我们最多30颜色,那么我们可以把这30中颜色用二进制储存和传给祖先节点,二进制的每一位 ...
- hdu 5023 线段树延迟更新+状态压缩
/* 线段树延迟更新+状态压缩 */ #include<stdio.h> #define N 1100000 struct node { int x,y,yanchi,sum; }a[N* ...
- HDU 4893 线段树裸题
Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu 5023 线段树
成端更新+统计区间内的值 挺模板的题... 一开始没想起来用set统计,傻傻地去排序了[大雾 #include<iostream> #include<cstdio> #incl ...
随机推荐
- 最佳的MongoDB客户端管理工具
<最佳的MongoDB客户端管理工具> 作者:chszs,未经博主允许不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 一个好的MongoD ...
- 关于JavaScript代码的执行效率总结
Javascript是一门非常灵活的语言,我们可以随心所欲的书写各种风格的代码,不同风格的代码也必然也会导致执行效率的差异,开发过程中零零散散地接触到许多提高代码性能的方法,整理一下平时比较常见并且容 ...
- tmux终端工具
本文原始地址:http://www.cnblogs.com/chinas/p/7094172.html,转载请注明出处,谢谢!!! 1.介绍 tmux(终端复用工具):一个很有趣的工具,类似GNU S ...
- ASP.NET mvc下在Controller下action的跳转方式
在ASP.NET mvc下,action有多种挑战方式: return RedirectToAction("Index");//一个参数时在本Controller下 如果Redir ...
- React Native新手入门
前言 React Native是最近非常火的一个话题,想要学习如何使用它,首先就要知道它是什么. 好像面对一个新手全面介绍它的文章还不多,我就归纳一下所有的资料和刚入门的小伙伴一起来认识它~ 将从以下 ...
- CSS line-height应用
一.固定高度的容器,单行文本垂直居中 代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf- ...
- 怎么样通过编写Python小程序来统计测试脚本的关键字
怎么样通过编写Python小程序来统计测试脚本的关键字 通常自动化测试项目到了一定的程序,编写的测试代码自然就会很多,如果很早已经编写的测试脚本现在某些基础函数.业务函数需要修改,那么势必要找出那些引 ...
- Exif xss
这种XSS出现的状况会特别少. Exif是啥??? 可交换图像文件格式(英语:Exchangeable image file format,官方简称Exif),是专门为数码相机的照片设定的,可以记录数 ...
- ProtocolBuffer 使用及 一些坑
Protocol Buffers,是Google公司开发的一种数据描述语言,类似于XML能够将结构化数据序列化,可用于数据存储.通信协议等方面. ProtocolBuffer的优势 跨平台: Prot ...
- mysql中间件 -> Atlas简介&安装
Atlas简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基础上, ...