HDU 5023 A Corrupt Mayor's Performance Art (线段树)

战舰V3移植CANopenNode并驱动电机全流程 第三部分是电机的对象字典(也就是节点的OD)中的索引,长度2个字节。索引发送的是小段模式,比如这一部分为0X40 0X60,实际操作的索引地址为0X6040。第一部分是COB-ID,长度1个字节,电机的node-ID默认为0x01,所以报文ID一直是601。第五部分是要写入的数据,数据发送的时候是小端模式,低字节数据先发送,长度由第二部分决定。配置定时器6,时间为1ms,根据公式计算得到参数PSC取72-1,ARR取1000-1。第二部分是CMD,长度1个字节,其实就是数据部分的长度, 阅读详情

Problem Description
Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed a safe way for mayor X to make money.

Because a lot of people praised mayor X's painting(of course, X was a mayor), mayor X believed more and more that he was a very talented painter. Soon mayor X was not satisfied with only making money. He wanted to be a famous painter. So he joined the local painting associates. Other painters had to elect him as the chairman of the associates. Then his painting sold at better price.

The local middle school from which mayor X graduated, wanted to beat mayor X's horse fart(In Chinese English, beating one's horse fart means flattering one hard). They built a wall, and invited mayor X to paint on it. Mayor X was very happy. But he really had no idea about what to paint because he could only paint very abstract paintings which nobody really understand. Mayor X's secretary suggested that he could make this thing not only a painting, but also a performance art work.

This was the secretary's idea:

The wall was divided into N segments and the width of each segment was one cun(cun is a Chinese length unit). All segments were numbered from 1 to N, from left to right. There were 30 kinds of colors mayor X could use to paint the wall. They named those colors as color 1, color 2 .... color 30. The wall's original color was color 2. Every time mayor X would paint some consecutive segments with a certain kind of color, and he did this for many times. Trying to make his performance art fancy, mayor X declared that at any moment, if someone asked how many kind of colors were there on any consecutive segments, he could give the number immediately without counting.

But mayor X didn't know how to give the right answer. Your friend, Mr. W was an secret officer of anti-corruption bureau, he helped mayor X on this problem and gained his trust. Do you know how Mr. Q did this?
 

Input
There are several test cases.

For each test case:

The first line contains two integers, N and M ,meaning that the wall is divided into N segments and there are M operations(0 < N <= 1,000,000; 0<M<=100,000)

Then M lines follow, each representing an operation. There are two kinds of operations, as described below:

1) P a b c
a, b and c are integers. This operation means that mayor X painted all segments from segment a to segment b with color c ( 0 < a<=b <= N, 0 < c <= 30).

2) Q a b
a and b are integers. This is a query operation. It means that someone asked that how many kinds of colors were there from segment a to segment b ( 0 < a<=b <= N).

Please note that the operations are given in time sequence.

The input ends with M = 0 and N = 0.
 

Output
For each query operation, print all kinds of color on the queried segments. For color 1, print 1, for color 2, print 2 ... etc. And this color sequence must be in ascending order.
 

Sample Input
5 10 P 1 2 3 P 2 3 4 Q 2 3 Q 1 3 P 3 5 4 P 1 2 7 Q 1 3 Q 3 4 P 5 5 8 Q 1 5 0 0
 

Sample Output
4 3 4 4 7 4 4 7 8
 



不好意思,代码不好看

代码:


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
using namespace std;

#define N  1000005

struct stud{
int le,ri;
int color;
bool cover;
}f[N*4];

int sum;
int n,t,m;
int b[35];

void fddd(int x)
{
	int nn=1,mm;

	while(x)
	{
		mm=x&1;
		if(mm) b[nn]=1;
		x>>=1;
		nn++;
	}

}

void build(int pos,int le,int ri)
{
    f[pos].le=le;
    f[pos].ri=ri;
    f[pos].cover=true;
    f[pos].color=1<<2;
    if(le==ri) return ;

    int mid=MID(le,ri);

    build(L(pos),le,mid);
    build(R(pos),mid+1,ri);
}

void update(int pos,int le,int ri,int v)
{
    if(f[pos].le>=le&&f[pos].ri<=ri)
    {
        f[pos].color=v;
        f[pos].cover=true;
        return ;
    }

    if(f[pos].cover)
    {
        f[L(pos)].color=f[pos].color;
        f[L(pos)].cover=true;

        f[R(pos)].color=f[pos].color;
        f[R(pos)].cover=true;

        f[pos].cover=false;
    }

    int mid=MID(f[pos].le,f[pos].ri);

    if(mid>=ri)
        update(L(pos),le,ri,v);
    else
        if(mid<le)
        update(R(pos),le,ri,v);
    else
    {
        update(L(pos),le,mid,v);
        update(R(pos),mid+1,ri,v);
    }

    f[pos].color=f[L(pos)].color|f[R(pos)].color;
}

void query(int pos,int le,int ri)
{
    if(f[pos].le>=le&&f[pos].ri<=ri)
    {
       sum|=f[pos].color;
        return ;
    }

    if(f[pos].cover)
    {
        f[L(pos)].color=f[pos].color;
        f[L(pos)].cover=true;

        f[R(pos)].color=f[pos].color;
        f[R(pos)].cover=true;

        f[pos].cover=false;
    }

    int mid=MID(f[pos].le,f[pos].ri);

    if(mid>=ri)
        query(L(pos),le,ri);
    else
        if(mid<le)
        query(R(pos),le,ri);
    else
    {
        query(L(pos),le,mid);
        query(R(pos),mid+1,ri);
    }

}

int main()
{
    int i;
    char c[10];
    while(scanf("%d%d",&n,&m),n+m)
    {
        build(1,1,n);
        int le,ri,v;
        int temp;

        while(m--)
        {
            scanf("%s",c);
            if(c[0]=='P')
            {
                scanf("%d%d%d",&le,&ri,&v);
                if(le>ri){temp=le; le=ri; ri=temp;}
                update(1,le,ri,1<<v);
            }
            else
            {
                 scanf("%d%d",&le,&ri);
                 if(le>ri){temp=le; le=ri; ri=temp;}

                 memset(b,0,sizeof(b));
				 sum=0;
                 query(1,le,ri);

                 fddd(sum);

                 int num=0;
                 for(i=0;i<35;i++)
				 {


				 	if(b[i])
					{
					 if(num) printf(" ");
					  printf("%d",i-1);
					  num=1;
				     }
				 }
				 printf("\n");
            }
        }
    }
    return 0;
}




Win11移动热点连接故障排查:从IP配置失败到网络共享的全面解决指南 本文提供了Win11移动热点连接故障的全面排查指南,重点解决手机连接时卡在“获取IP地址”或提示“IP配置失败”的问题。文章从基础检查(如确认网络连接、选择正确共享源)入手,深入讲解了核心的网络适配器共享设置、关键系统服务检查、防火墙配置以及终极解决方案——网络重置。通过系统性的步骤,帮助用户彻底修复Win11移动热点无法共享网络的问题。 阅读详情

相关推荐

10位PWM能否满足电梯±5mm平层精度?4位扩展法让10位PWM达到14位精度

电梯平层精度直接关系乘坐舒适性与安全性,而PWM分辨率是决定精度的关键因素之一。10位PWM能否满足±5mm的平层精度要求?本文从分辨率与物理量的对应关系出发,结合工程精度需求与实战对比,给出明确的选型结论与解决方案,请参考优快云博客《4位扩展法:基于ATtiny816的高精度PWM软件扩展方法》和《低成本高精度PWM:4位扩展法原理、实现和工程实践》。10位PWM的分辨率为 $2^{10} = 1024$ 级。

m0_73354873的博客 243

iPad 3」はフロントに「Face Time HD」カメラを採用し3月発売か紹介

iPad 3」はフロントに「Face Time HD」カメラを採用し3月発売か紹介 9 to 5 Macによると、独自のApple情報網を持っているiLoungeのJeremy Horwitz氏が次期iPadに関する情報をツィートしているそうです。その情報をまとめると、次期iPadはカメラの性能が向上し、フロントカメラはFace Time HDカメラになり、バックカメラはiPhone ...

weixin_30773135的博客 11万+

基于GPU的GEMM矩阵相乘运算优化

从上图中我们可以看到三种处理方法。第一种是将A和B矩阵分块,第二种方法是将C和B矩阵分块,第三种方法是将C和A矩阵分块。GEMM的子任务是GEPP或GEMP;最小粒度的任务是GEBP或GEPB或点乘。

weixin_55035144的博客 2152

java h d,Java, {Country} Hướng dẫn du lịch | Những việc nên làm tại Java, {Country} | Jetstar | Jets...

Là một trong những đảo nhỏ nhất của Indonesia nhưng cũng như các nơi khác trên khắp đất nước, Java được thiên nhiên ban tặng cảnh đẹp tự nhiên phong phú, từ bãi biển hoang sơ như Kepulauan Seribu trên...

weixin_34547628的博客 6万+

论文笔记:基于对比学习的半监督分类学习方法

论文阅读笔记_CCSSL

weixin_46224126的博客 3312

使用sklearn学习多项式回归(三)

1,什么是线性 我们无数次提到”线性“这个名词。在支持向量机中,我们也曾经提到最初的支持向量机只能够分割线性可分的数据,然后引入了”核函数“来帮助我们分类那些非线性可分的数据。我们也曾经说起过,比如说决策树,支持向量机是”非线性“模型。所有的这些概念,让我们对”线性“这个词非常熟悉,却又非常陌生——因为我们并不知道它的真实含义。接下来我们看看线性回归模型改进的核心之一:帮助线性回归解决非线性问题。 1.1,变量之间的线性关系 ”线性“这个词用于描述不同事物时有着不同的含义。我们最常使用的线性是指“变量

理科男同学 5100

HDOJ-1702 栈和队列问题[或模拟]

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1697    Accepted Submission(s): 906 Problem Description ACboy wa...

weixin_34226182的博客 550

深入解析EDID中Display Descriptor Block的配置技巧与实战应用

本文深入解析EDID中Display Descriptor Block的配置技巧与实战应用。通过剖析像素时钟、有效像素、消隐区与同步脉冲等核心参数,并结合1280x720@60Hz的实战配置案例,指导开发者如何正确为定制硬件或非标准显示器编写“身份证”,避免黑屏、分辨率异常等问题,确保显示设备完美点亮。

1a2s3d4f5g的博客 878

JAVA集合

Set集合 一、感性认知: 1、对比List集合来看Set集合,感受差异化,想象距离任意情景,比较何时用List集合,何时用 Set集合。 二、理性认知: 1、集合结构图 a、java.util.Collection[I] java.util.List[I] java.util.ArrayList[C] java.util.LinkedList[C] java.util.Vect...

TracyEminem的博客 4万+

qq邮箱发错误:The “From“ header is missing or invalid. Please follow RFC5322, RFC2047, RFC822 standard pro

如果还报错 (550, b’The mail may contain inappropriate words or content.'),可能是你message[‘From’]中的< senderxxx@qq.com >发送邮箱填错了,必须要和self.sender = ’ senderxxx@qq.com '一样。可能是之前qq邮箱发送协议存在漏洞,可隐藏发送者邮箱。现在换了新协议,导致与原来协议规则、编码出现了一些问题。"python自动发送""python自动发送"

云霄IT的博客 3670

YOLOv8 超参数调优教程! 使用Ray Tune进行高效的超参数调优!

YOLOv8超参数调优教程!😎 使用Ray Tune进行高效的超参数调优!

Coding... 1万+

c#学习笔记(1)

C#学习笔记1, 结构(struct) 与 类(class)[attributes] [modifiers] struct identifier [:interfaces] body [;]结构与类很相似,都表示可以包含数据成员和函数成员的数据结构。与类不同的是,结构是值类型并且不需要堆分配。结构类型的变量直接包含结构的数据,而类类型的变量包含对数据的引用(该变量称为对象)。 struct 类型适

michaelhawn的专栏 1577

国科大学习资料--图像处理(彭思龙、杨戈)--2020年期末考试题解析(学长整理分析)

在对20年卷子分析前,先看看19年卷子的解析(后面有20年的变化,由于从核心课调整到了普及课,20年的卷子相对简单,但是还是有很多细节) 解析:(字写的不好别嫌弃!!!!) 20年的卷子 第一题:和19年基本一致,但是加了高斯核计算费用,要算一个节省计算成本比率,所以去多看看PPT 第二题:和19年基本一致,加了证明两个高斯卷积仍然是高斯卷积,相当于19年题2和3结合 第三题:采样定理,和19年基本一致,但要注意加了证明 第四题:考了形态学提取图像边界 第五题:直方图,和19年一

无名何许人的博客 4364

HDU5023 A Corrupt Mayor's Performance Art 【线段树】

A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submission(s): 507    Accepted Submission(s): 203 Problem Descr

长风的专栏 1397

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

A Corrupt Mayor's Performance Art 线段树 hdu 5023

Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this s...

loooooog的博客 200

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

hdu-5023 A Corrupt Mayor's Performance Art (线段树区间修改)

今天集训队打比赛的一道题,很明显是个线段树,我们队照着lrj蓝书敲了一通,机智的将修改值和加和改成了位运算:|=  但是好像哪里出了点小问题,就是不对,赛后又水了一遍,竟然过了。。。发现还是lrj的书好啊,市面上的模板一点也不好用,连区间修改都没有 。  等集训完了要静心好好系统的学习一下线段树 。 多看多刷lrj的书 。 细节参见代码: #include using namespace

AC_Arthur的专栏 951

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

【HDU】5023 A Corrupt Mayor's Performance Art 线段树

传送门:【HDU】5023 A C【HDU】5023 A Corrupt Mayor's Performance Artorrupt Mayor's Performance Art【HDU】5023 A Corrupt Mayor's Performance Art

poursoul 776

HDU 5023 A Corrupt Mayor's Performance Art(线段树)

Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed

The_star_is_at的博客 459

HDU 5023 A Corrupt Mayor's Performance Art (线段树区间更新,入门详解)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 题面: A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submis

David_Jett 836

hdu5023 A Corrupt Mayor's Performance Art(线段树+区间更新)

hdu5023题目P :A到B区间图上第C种颜色; Q:A到B所有点存在的颜色种类;思路因为只有30种颜色,可以用位运算进行状态压缩,线段树就是区间更新,区间查询。代码#include <iostream> #include <cstdio> #include <algorithm> #include <cstring>#define lson l, m , rt << 1 #define rso

天道酬勤 495

HDU - 5023 A Corrupt Mayor's Performance Art 线段树 按位记录颜色

A Corrupt Mayor's Performance ArtTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others)Total Submission(s): 2984    Accepted Submission(s): 1070Problem DescriptionCorrup...

Uniontake 195

HDU 5023 A Corrupt Mayor's Performance Art (线段树)

A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submission(s): 255    Accepted Submission(s): 114 Problem Descrip

u012150279的专栏 1106

Hdu5023_A Corrupt Mayor's Performance Art(线段树区间染色+区间查询)

题意: 一块色板上只能做两件事:1. “P A B C” 指在A到 B 号方格中涂上颜色 C。2. “Q A B” 指老师的提问:A到 B号方格中有哪几种颜色。初始时全部涂成2号颜色。 思路: 常规的线段树区间染色。 #include <cstdio> #include <cstring> #include <algorithm> #define lson ro...

CY05627的博客 336

hdu 5023 A Corrupt Mayor's Performance Art(线段树)

题目链接:hdu 5023 A Corrupt Mayor's Performance Art 题目大意:给定一段区间,初始颜色为2,接诊有N次操作,P:将区间l,r涂成c,Q:查询l,r之间有哪些颜色按字典序输出。 解题思路:因为颜色的种数只有30,对于每个节点之间用一个二进制数记录即可,水水的线段树。 #include #include #include #include

不慌不忙、不急不躁 621

hdu 5023 A Corrupt Mayor's Performance Art(线段树区间合并)

题意: 刚刚开始的时候所有的片段上的颜色都是2。 在片段上着色,有两种操作,如下: 第一种:P a b c 把 a 片段至 b 片段的颜色都变为 c 。 第二种:Q a b 询问 a 片段至 b 片段有哪些颜色,把这些颜色按从小到大的编号输入,不要有重复。 解析: 很简单的线段树区间合并问题。 对于1操作,可以利用线段树进行区间覆盖。 对于2操作,每查询到一个有

小G的ACM之路 715

HDU5023 - A Corrupt Mayor's Performance Art(线段树)

题目链接: HDU5023 【题意】给出n段

转移到dawxy.com 708
上一篇: HDU 5024 Wang Xifeng's Little Plot (bfs)
下一篇: HDU 5025 Saving Tang Monk(bfs)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值