社区讨论

请求开大空间限制

P1558色板游戏参与者 5已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@m5t3wo3c
此快照首次捕获于
2025/01/12 12:20
去年
此快照最后确认于
2025/01/12 17:13
去年
查看原帖
二十分钟后@管理
CPP
#include<cstdio>
#include<algorithm>
// #define int short
using namespace std;

int n,q,p;
struct node
{
	int l,r;
	node *lson,*rson;
	bool tot,full0,full1;
	bool set_tag,unset_tag;
	node(){}
	node(int l,int r):l(l),r(r),lson(nullptr),rson(nullptr),tot(0),full0(1),full1(0),set_tag(0),unset_tag(0){}
} *color[35];

#define init \
	int &l=Node->l,&r=Node->r; \
	node *&lson=Node->lson, *&rson=Node->rson; \
	bool &tot=Node->tot,&full0=Node->full0,&full1=Node->full1; \
	bool &set_tag=Node->set_tag,&unset_tag=Node->unset_tag;

inline void upd(node *Node)
{
	init;
	int mid=l+r>>1;
	if(lson==nullptr)
		lson=new node(l,mid);
	if(rson==nullptr)
		rson=new node(mid+1,r);
}

inline void set(node *Node,bool v)
{
	init;
	tot=v;
	full0=!v;
	full1=v;
	set_tag=v;
	unset_tag=1;
}

inline void pushdown(node *Node)
{
	init;
	if(l==r||!unset_tag)
		return;
	upd(Node);
	set(lson,set_tag);
	set(rson,set_tag);
	unset_tag=0;
}

inline void pushup(node *Node)
{
	init;
	if(l==r)
		return;
	upd(Node);
	tot=lson->tot||rson->tot;
	full0=lson->full0&&rson->full0;
	full1=lson->full1&&rson->full1;
}

inline void modify(node *Node,int x,int y,bool v)
{
	init;
	if(x<=l&&r<=y)
	{
		set(Node,v);
		return;
	}
	if(y<l||r<x)
		return;
	upd(Node);
	pushdown(Node);
	modify(lson,x,y,v);
	modify(rson,x,y,v);
	pushup(Node);
}

inline bool query(node *Node,int x,int y)
{
	init;
	if(x<=l&&r<=y)
		return tot;
	if(y<l||r<x)
		return 0;
	if(full0)
		return 0;
	if(full1)
		return 1;
	upd(Node);
	pushdown(Node);
	if(query(lson,x,y))
		return 1;
	return query(rson,x,y);
}

inline int read() {
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9')f=c=='-'?-1:1,c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-'0',c=getchar();
	return x*f;
}

signed main()
{
	// scanf("%d%d%d",&n,&p,&q);
	n=read(),p=read(),q=read();
	for(int i=1;i<=p;++i)
		color[i]=new node(1,n);
	modify(color[1],1,n,1);
	while(q--)
	{
		char op=getchar();
		if(op=='C')
		{
			int l,r,col;
			// scanf("%d%d%d",&l,&r,&col);
			l=read(),r=read(),col=read();
			if(l>r)
				swap(l,r);
			for(int i=1;i<=p;++i)
				modify(color[i],l,r,0);
			modify(color[col],l,r,1);
		}
		else if(op=='P')
		{
			int l,r;
			// scanf("%d%d",&l,&r);
			l=read(),r=read();
			if(l>r)
				swap(l,r);
			int ans=0;
			for(int i=1;i<=p;++i)
				ans+=query(color[i],l,r);
			if(ans>=10)
				putchar(ans/10+'0');
			putchar(ans%10+'0');
			putchar('\n');
		}
		else ++q;
	}
	return 0;
}

回复

6 条回复,欢迎继续交流。

正在加载回复...