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 ...
随机推荐
- Swiper点击后自动轮播停止情况
用户操作swiper之后,是否禁止autoplay.默认为true:停止. 如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay. 操作包括触碰,拖动,点击 ...
- 用phpUnit入门TDD
用phpunit实战TDD系列 从一个银行账户开始 假设你已经 安装了phpunit. 我们从一个简单的银行账户的例子开始了解TDD(Test-Driven-Development)的思想. 在工程目 ...
- serialize()传值缺失
思路:serialize()获取的是 " & " 拼接的字符串,无法传值,需要拆分后,拼接,生成新字符串,传过去. 例子: var v_idd = $("form ...
- C语言入门教程-(1)简介及搭建环境
1.谁适合阅读本教程 本教程可以帮助大家从零开始学习C语言,对于有一定基础的人起到夯实基本功的作用.C语言容易学习,非常适合初学者入门,而且也为以后的编程打下基础.借用一句话:“要进入编程行业高手必学 ...
- c++刷题(18/100)树
题目1:二叉搜索树的第k个节点 给定一颗二叉搜索树,请找出其中的第k小的结点.例如, 5 / \ 3 7 /\ /\ 2 4 6 8 中,按结点数值大小顺序第三个结点的值为4. 思路:因为是二叉搜索树 ...
- Python概念-Item系列(林海峰教的)
这个Item系列是egon老师自创的,个人还是可以接受这种文化底蕴的,所以直接拿来用,也是毫无违和感的 所谓Attr系列,其实是__setattr__,__delattr__,__getattr__ ...
- 树形dp(B - Computer HDU - 2196 )
题目链接:https://cn.vjudge.net/contest/277955#problem/B 题目大意:首先输入n代表有n个电脑,然后再输入n-1行,每一行输入两个数,t1,t2.代表第(i ...
- 关于Unix/Linux的终端、伪终端、控制台和shell
历史是什么:是过去传到将来的回声,是将来对过去的反映. ——雨果(法)<笑面人> 阅读本文大概需要花费你15分钟 文章导航: 计算机的发展 UNIX系统的诞生 UNIX系统的发展 终端与控 ...
- 2016.07.13-map的使用(以leetcode1-Two Sum为例)
map的使用 1.unordered_map和map的区别 2.如何用 3.for (int a : nums1) 4.to_string() 5.map的应用 1.unordered_map和map ...
- mysql基准测试工具tpcc-mysql安装、使用、结果解读
TPCC是专门针对联机交易处理系统(OLTP系统)的规范,一般情况下我们也把这类系统称为业务处理系统,tpcc-mysql是percona基于TPC-C(下面简写成TPCC)衍生出来的产品,专用于My ...