题意:

给n,m,k,n长度,k个操作,m种颜色

操作C:输入A,B,C,区间【A,B】变成C颜色,可能A>B,所以要确保A<B

操作P:输入A,B,区间【A,B】的颜色种类

思路:

因为颜色只有30种,可以用位运算,然后进行lazy标记

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define it register int
#define inf 0x3f3f3f3f
#define lowbit(x) (x)&(-x)
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 998244353
const int maxn=1e6+;
int n,m,k;
int tree[maxn],lazy[maxn];
il void pushdown(int x){
if(lazy[x]){
tree[x<<]=lazy[x];tree[x<<|]=lazy[x];
lazy[x<<]=lazy[x];lazy[x<<|]=lazy[x];
lazy[x]=;
}
}
il void pushup(int x){
tree[x]=tree[x<<]|tree[x<<|];
}
void build(int x,int l,int r){
if(l==r){
tree[x]=;return;
}
int mid=(l+r)>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
pushup(x);
}
void update(int x,int l,int r,int l1,int r1,int zhi){
if(l1<=l && r<=r1){
pushdown(x);
int w=(ll)<<(zhi-);
lazy[x]=w;tree[x]=w;
return;
}
pushdown(x);
int mid=(l+r)>>;
if(l1<=mid){
update(x<<,l,mid,l1,r1,zhi);
}
if(r1>mid){
update(x<<|,mid+,r,l1,r1,zhi);
}
pushup(x);
}
int query(int x,int l,int r,int l1,int r1){
if(l1<=l && r<=r1){
return tree[x];
}
pushdown(x);
int temp=;
int mid=(l+r)>>;
if(l1<=mid){
temp|=query(x<<,l,mid,l1,r1);
}
if(r1>mid){
temp|=query(x<<|,mid+,r,l1,r1);
}
return temp;
}
int main(){
char c;
scanf("%d%d%d",&n,&m,&k);
build(,,n);
for(it i=;i<k;i++){
//getchar();
scanf("%s",&c);
if(c=='C'){
int A,B,C;
scanf("%d%d%d",&A,&B,&C);
if(A>B){swap(A,B);}
update(,,n,A,B,C);
}
else{
int A,B;
scanf("%d%d",&A,&B);
if(A>B){swap(A,B);}
int sum=query(,,n,A,B),ans=;
for(it j=;j<m;j++){
if(sum&(<<j)){ans++;}
}
printf("%d\n",ans);
}
}
return ;
}

这道题我wa了一个晚上,调了一个晚上,自闭了一个晚上

第二天早上,重写还是wa,实在是搞不定了,去看了题解。感觉没差,然后把题解交上ac????

然后照着题解写了一边又wa,???最后在讨论区瞧见了一个解释……

我举报这题坑爹。不过让我涨了%c %s getchar()的认知

这题用getchar();scanf("%c",&c);就是wa到死

换成scanf(" %c",&c);或者scanf("%s",&c);就AC

从未考虑这一块的我理所当然的用了getchar();还拼命找错,记住了

P1558 色板游戏 线段树(区间修改,区间查询)的更多相关文章

  1. [线段树]区间修改&区间查询问题

    区间修改&区间查询问题 [引言]信息学奥赛中常见有区间操作问题,这种类型的题目一般数据规模极大,无法用简单的模拟通过,因此本篇论文将讨论关于可以实现区间修改和区间查询的一部分算法的优越与否. ...

  2. 洛谷P1558 色板游戏 [线段树]

    题目传送门 色板游戏 题目背景 阿宝上学了,今天老师拿来了一块很长的涂色板. 题目描述 色板长度为L,L是一个正整数,所以我们可以均匀地将它划分成L块1厘米长的小方格.并从左到右标记为1, 2, .. ...

  3. SPOJ GSS2 - Can you answer these queries II(线段树 区间修改+区间查询)(后缀和)

    GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot ...

  4. Hdu 1698(线段树 区间修改 区间查询)

    In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...

  5. SPOJ BGSHOOT - Shoot and kill (线段树 区间修改 区间查询)

    BGSHOOT - Shoot and kill no tags  The problem is about Mr.BG who is a great hunter. Today he has gon ...

  6. P1558 色板游戏 (线段树)

    题目链接 Solution 一个简单的 或 线段树.竟然坑了我一个小时... 因为颜色很小,所以把状态压起来. 然后每个节点上的数值代表当前颜色状态. 然后节点合并很简单,直接或起来. 需要注意一下的 ...

  7. A Simple Problem with Integers POJ - 3468 线段树区间修改+区间查询

    //add,懒标记,给以当前节点为根的子树中的每一个点加上add(不包含根节点) // #include <cstdio> #include <cstring> #includ ...

  8. P1558 色板游戏 线段树+二进制状压

    好,这个想法是我想拿去做HH的项链的.但是那个颜色有十万种...直接爆. 做这个倒是so easy 被两个地方坑了.1,a,b可能大小相反. 2,ask之前要down一波,我没down就挂了..... ...

  9. I Hate It(线段树点修改区间查询)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 I Hate It Time Limit: 9000/3000 MS (Java/Others) ...

随机推荐

  1. 微信小程序CSS之Flex布局

    转载:https://blog.csdn.net/u012927188/article/details/83040156 相信刚开始学习开发小程序的初学者一定对界面的布局很困扰,不知道怎么布局,怎么摆 ...

  2. Linux运维--14.Kolla部署OpenStack使用external MariaDB Galera Cluster

    使用haproxy+keepalived实现Mariadb负载均衡 controller2: 10.100.2.52 haproxy+keepalived controller3: 10.100.2. ...

  3. Nginx 配置Websocket

    Nginx反向代理配置websocket nginx.org 官网推荐如下的配置,也可以直接看官网:http://nginx.org/en/docs/http/websocket.html http ...

  4. C++——动态内存分配2-创建对象数组

    //创建对象数组 #include<iostream> using namespace std; class Point { public:        Point()       {  ...

  5. python求极值点(波峰波谷)

    python求极值点主要用到scipy库. 1. 首先可先选择一个函数或者拟合一个函数,这里选择拟合数据:np.polyfit import pandas as pd import matplotli ...

  6. doctype的意思

    <!DOCTYPE HTML>这句话在整个网页的最上头,意思是这个网页是一个用html5语法写的,因为还有html4和xhtml等语法. 为了兼容一些旧的页面,浏览器设置了两种解析模式:1 ...

  7. Centos7更改网卡名称Eth0

    标签: Centos7更改网卡名称 2016-12-06 21:55 8737人阅读 评论(1) 收藏 举报  分类: linux(6)  作者同类文章X 版权声明:本文为博主原创文章,未经博主允许不 ...

  8. Centsos7 aria2

    wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/aria2.sh & ...

  9. pytest学习2-运行方式

    pytest常用运行方式 运行目录及子包下的所有用例: pytest 目录名 运行指定模块所有用例: pytest test_reg.py pytest test_reg.py::TestClass: ...

  10. [NOI2014] 魔法森林 - Link Cut Tree

    [NOI2014] 魔法森林 Description 给定一张图,每条边 \(i\) 的权为 \((a_i,b_i)\), 求一条 \(1 \sim n\) 路径,最小化 \(\max_{i\in P ...