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 ...
随机推荐
- linux nginx服务 反向代理 负载均衡 nfs服务
一.nginx服务 1.首先软件停用firewall #systemctl stop firewalld stop:本次停用 disable:开机停用 enable:开机启用 #ps aux | gr ...
- 微服务深入浅出(9)-- Nginx
Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,处理请求是异步非阻塞的,多个连接(万级别)可以对应一个进程.而Apache是同步多进程模型,一个连接对 ...
- HTML字体的设置
CSS字体设置 box-sizing:border #content-box box-shadow:设置盒子边框的阴影. 字体动作: font-family:设置字体.比如:‘微软雅黑 ...
- Java 8 Lambda表达式,让你的代码更简洁
Lambda表达式是Java 8一个非常重要的新特性.它像方法一样,利用很简单的语法来定义参数列表和方法体.目前Lambda表达式已经成为高级编程语言的标配,像Python,Swift等都已经支持La ...
- yii验证系统学习记录,基于yiicms(一)写的太长了,再写一篇(二)
项目地址:https://gitee.com/templi/yiicms 感谢七觞酒大神的付出,和免费分享.当然也感谢yii2的开发团队们. 项目已经安全完毕,不知道后台密码,这种背景下,后台无法进去 ...
- 2016.5.24——Intersection of Two Linked Lists
Intersection of Two Linked Lists 本题收获: 1.链表的输入输出 2.交叉链表:这个链表可以有交叉点,只要前一个节点的的->next相同即可. 题目:Inters ...
- Redis简介——(一)
1.关于关系型数据库和nosql数据库 关系型数据库是基于关系表的数据库,最终会将数据持久化到磁盘上,而nosql数据 库是基于特殊的结构,并将数据存储到内存的数据库.从性能上而言,nosql数据库 ...
- 10 Useeful Tips for Writing Effective Bash Scripts in Linux
1.Always Use Comments in Scripts2.Make a Scripts exit When Fails Sometimes bash may continue to e ...
- reshape中的-1
>>> a = np.array([[1,2,3], [4,5,6]]) >>> np.reshape(a, (3,-1)) # the unspecified v ...
- shell脚本实现监控shell脚本的执行流程及变量的值
这篇文章主要介绍了shell脚本实现监控shell脚本的执行流程及变量的值本文使用shell完成对执行过程中条件语句中的变量的变化的监控和整个程序的执行流程的观察功能,需要的朋友可以参考下 很多时候, ...