比赛 2025.6.21 评测结果 AAAAAAAAAA
题目名称 色板游戏 最终得分 100
用户昵称 徐诗畅 运行时间 1.101 s
代码语言 C++ 内存使用 5.89 MiB
提交时间 2025-06-21 11:23:43
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,T,q,t[N<<2],tag[N<<2];
void push_up(int p){t[p]=t[p<<1]|t[p<<1|1];}
void addtag(int p,int d){
	t[p]=(1<<d);
	tag[p]=d;
}
void push_down(int p,int l,int r){
	if(tag[p]){
		addtag(p<<1,tag[p]);
		addtag(p<<1|1,tag[p]);
		tag[p]=0;
	}
}
void update(int p,int l,int r,int L,int R,int d){
	if(L<=l&&R>=r){
		addtag(p,d);
		return;
	}
	push_down(p,l,r);
	int mid=(l+r)>>1;
	if(L<=mid) update(p<<1,l,mid,L,R,d);
	if(R>mid) update(p<<1|1,mid+1,r,L,R,d);
	push_up(p);
}
int query(int p,int l,int r,int L,int R){
	if(L<=l&&R>=r) return t[p];
	push_down(p,l,r);
	int mid=(l+r)>>1;
	int ans=0;
	if(L<=mid) ans|=query(p<<1,l,mid,L,R);
	if(R>mid) ans|=query(p<<1|1,mid+1,r,L,R);
	return ans;
}
void build(int p,int l,int r){
	if(l==r){t[p]=2; return;}
	int mid=(l+r)>>1;
	build(p<<1,l,mid); build(p<<1|1,mid+1,r);
	push_up(p);
}
signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%lld%lld%lld",&n,&T,&q);
	build(1,1,n);
	while(q--){
		char op; cin>>op;
		if(op=='C'){
			int l,r,x; scanf("%lld%lld%lld",&l,&r,&x);
			if(l>r) swap(l,r);
			update(1,1,n,l,r,x);
		}
		else{
			int l,r; scanf("%lld%lld",&l,&r); 
			if(l>r) swap(l,r);
			printf("%lld\n",__builtin_popcount(query(1,1,n,l,r)));
		}
	}
	return 0;
}