样例过,全wa,蒟蒻求调
  • 板块P1558 色板游戏
  • 楼主elswzl
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/7/27 13:15
  • 上次更新2023/10/27 18:11:22
查看原帖
样例过,全wa,蒟蒻求调
672877
elswzl楼主2022/7/27 13:15
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
using namespace std;
const int N=1e5+10;
long long n,o,num;
struct node{
	long long l,r,sum,lazy;
}t[N<<2];
long long lowbit(int x){
	return x&(-x);
}
void pushup(int p){
	t[p].sum=t[p*2].sum|t[p*2+1].sum;
	return ;
}
void pushdown(int p){
	if(t[p].lazy){
		t[p*2].lazy=t[p].lazy;
		t[p*2+1].lazy=t[p].lazy;
		t[p*2].sum=t[p].lazy;
		t[p*2+1].sum=t[p].lazy;
		t[p].lazy=0;
	}
	return ;
}
void build(int p,int l,int r){
	t[p].l=l;	t[p].r=r;	t[p].sum=1;
	if(l==r)return ;
	int mid=l+r>>1;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	return ;
}
void add(int p,int L,int R,int c){
	if(t[p].l>=L&&t[p].r<=R){
		pushdown(p);//0000000000
		t[p].sum=1<<(c-1);
		t[p].lazy=1<<(c-1);
		return ;
	}
	int mid=t[p].l+t[p].r>>1;
	if(mid>=L)add(p*2,L,R,c);
	if(mid<R)add(p*2+1,L,R,c);
	pushup(p);
	return ;
}
long long query(int p,int L,int R){
	if(t[p].l>=L&&t[p].r<=R){
		pushdown(p);
		return t[p].sum;
	}
	pushdown(p);
	int mid=t[p].l+t[p].r>>1;//100000000000000000000000001
	int ret=0;
	if(mid>=L)ret=ret|query(p*2,L,R);
	if(mid<R)ret=ret|query(p*2+1,L,R);
	return ret;
}
int main(){
	cin>>n>>num>>o;
	build(1,1,n);
	for(int i=1;i<=o;i++){
		char cp;	int x,y;	scanf("%s%d%d",&cp,&x,&y);
		if(x>y){
			x=y+x;
			y=x-y;
			x=x-y;
		}
		if(cp=='C'){
			
			int z;	scanf("%d",&z);
			add(1,x,y,z);
			
		}
		else{
			long long ans=query(1,x,y);
			int ret=0;
			for(long long i=ans;i;i-=lowbit(i))ret+=1;
			cout<<ret<<endl;
		}
	}
	return 0;
}

RT

2022/7/27 13:15
加载中...