社区讨论
only AC hack求调
P1558色板游戏参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mlm223bc
- 此快照首次捕获于
- 2026/02/14 16:29 5 天前
- 此快照最后确认于
- 2026/02/14 16:31 5 天前
CPP
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5,Mod=998244353;
int tr[N<<2],tag[N<<2];
int L,T,O;
void pushup(int idx)
{
tr[idx]=tr[idx<<1]|tr[idx<<1|1];
}
void apply(int idx,int x)
{
tr[idx]=1LL<<(x-1);
tag[idx]=x;
}
void pushdown(int idx)
{
if(tag[idx])
{
apply(idx<<1,tag[idx]);
apply(idx<<1|1,tag[idx]);
tag[idx]=0;
}
}
void build_tree(int idx,int l,int r)
{
if(l==r)
{
tr[idx]=1;
return ;
}
int m=l+r>>1,lch=idx<<1,rch=idx<<1|1;
build_tree(lch,l,m),build_tree(rch,m+1,r);
pushup(idx);
}
void modify(int pos,int l,int r,int sl,int sr,int x)
{
if(sl<=l&&r<=sr)
{
apply(pos,x);
return ;
}
pushdown(pos);
int mid=l+r>>1;
if(sl<=mid)
{
modify(pos<<1,l,mid,sl,sr,x);
}
if(sr>mid)
{
modify(pos<<1|1,mid+1,r,sl,sr,x);
}
pushup(pos);
}
int query(int idx,int l,int r,int sl,int sr)
{
if(l<=sl&&r>=sr)
{
return tr[idx];
}
pushdown(idx);
int mid=l+r>>1;
int res=0;
if(sl<=mid)
{
res|=query(idx<<1,l,mid,sl,sr);
}
if(sr>mid)
{
res|=query(idx<<1|1,mid+1,r,sl,sr);
}
return res;
}
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>L>>T>>O;
build_tree(1,1,L);
char op;
for(int i=1,a,b,c;i<=O;i++)
{
cin>>op>>a>>b;
if(a>b)
{
swap(a,b);
}
if(op=='C')
{
cin>>c;
modify(1,1,L,a,b,c);
}
else
{
int res=query(1,1,L,a,b);
cout<<__builtin_popcountll(res)<<endl;
}
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...