社区讨论
RE求助
P1558色板游戏参与者 3已保存回复 8
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @lo7wehza
- 此快照首次捕获于
- 2023/10/27 08:51 2 年前
- 此快照最后确认于
- 2023/10/27 08:51 2 年前
CPP
#include<iostream>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 10;
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int L,T,O;
struct node{
ll l,r;
ll color;
ll lazy;
}tree[MAXN << 2];
void spread(int p){
if(tree[p].lazy){
tree[p << 1].color = tree[p].lazy;
tree[p << 1 | 1].color = tree[p].lazy;
tree[p << 1].lazy = tree[p].lazy;
tree[p << 1 | 1].lazy = tree[p].lazy;
tree[p].lazy = 0;
}
}
void build(ll p,ll l,ll r){
tree[p].l = l,tree[p].r = r;
tree[p].color = 1;
if(l == r)
return ;
ll mid = (l + r) >> 1;
build(p << 1,l,mid);
build(p << 1 | 1,mid + 1,r);
return ;
}
void change(ll p,ll l,ll r,ll col){
if(tree[p].l >= l && tree[p].r <= r){
tree[p].color = 1 << col;
tree[p].lazy = 1 << col;
return ;
}
spread(p);
ll mid = (tree[p].l + tree[p].r) >> 1;
if(l <= mid) change(p << 1,l,r,col);
if(r > mid) change(p << 1 | 1,l,r,col);
if(tree[p << 1].color != tree[p << 1 | 1].color){
tree[p].color = 0;
for(int i = 1 ; i <= T ; i ++){
if((tree[p << 1].color & (1 << i)) || (tree[p << 1 | 1].color & (1 << i)))
tree[p].color += 1 << i;
}
}
else {
tree[p].color = tree[p << 1].color;
}
}
ll ask(ll p,ll l,ll r){
cout << 1;
if(tree[p].l >= l && tree[p].r <= r){
return tree[p].color;
}
spread(p);
ll mid = (l + r) >> 1;
ll ans = 0;
ll f1,f2;
if(l <= mid) f1 = ask(p << 1,l,r);
if(r > mid) f2 = ask(p << 1 | 1,l,r);
for(int i = 1 ; i <= T ; i ++){
if((f1 & (1 << i)) || (f2 & (1 << i)))
ans += 1 << i;
}
return ans;
}
int main(){
L = read(),T = read(),O = read();
build(1,1,L);
int ans;
for(int i = 1,a,b,c ; i <= O ; i ++){
char ch;
cin >> ch;
a = read(),b = read();
if(a > b)
swap(a,b);
if(ch == 'C'){
c = read();
change(1,a,b,c);
} else {
int data = ask(1,a,b);
for(int i = 1 ; i <= T ; i ++){
if(data & (1 << i))
ans ++;
}
cout << ans << endl;
}
}
return 0;
}
回复
共 8 条回复,欢迎继续交流。
正在加载回复...