社区讨论

线段树求调,玄关 WA on Subtask 1

P4979矿洞:坍塌参与者 1已保存回复 0

讨论操作

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

当前回复
0 条
当前快照
1 份
快照标识符
@mlkr1ukw
此快照首次捕获于
2026/02/13 18:33
6 天前
此快照最后确认于
2026/02/16 23:55
3 天前
查看原帖
CPP
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <iomanip>
#include <string>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <cstdint>
#include <cfloat>
#include <vector>
#include <ctime>
#include <random>

using namespace std;
const int maxn=5e5+10;
struct node
{
	char c='\0';
	bool s=0;
	char g='\0';
}tree[maxn<<2];
int n;
char s[maxn];
void push_up(int c)
{
	if(tree[c*2].s&&tree[c*2+1].s&&tree[c*2].c==tree[c*2+1].c)
	{
		tree[c].c=tree[c*2].c;
		tree[c].s=1;
		tree[c].g='\0';
	}
	else
	{
		tree[c].c='\0';
		tree[c].s=0;
		tree[c].g='\0';
	}
}
void build(int l,int r,int c)
{
	if(l==r)
	{
		tree[c].c=s[l];
		tree[c].s=1;
		tree[c].g='\0';
		return ;
	}
	int mid=l+(r-l)/2;
	build(l,mid,c*2);
	build(mid+1,r,c*2+1);
	push_up(c);
}
void change(int l,int r,int tl,int tr,int c,char g);
void push_down(int c,int l,int r,int mid)
{
	if(tree[c].g!='\0')
	{
		change(l,mid,l,mid,c*2,tree[c].g);
		change(mid+1,r,mid+1,r,c*2+1,tree[c].g);
		tree[c].g='\0';
	}
}
void change(int l,int r,int tl,int tr,int c,char g)
{
	if(l>tr||r<tl)
	{
		return ;
	}
	if(tl<=l&&r<=tr)
	{
		tree[c].c=g;
		tree[c].s=1;
		tree[c].g=g;
		return ;
	}
	int mid=l+(r-l)/2;
	push_down(c,l,r,mid);	
	change(l,mid,tl,tr,c*2,g);
	change(mid+1,r,tl,tr,c*2+1,g);
	push_up(c);
}
char gl(int l,int r,int tl,int tr,int c)
{
	if(l>tr||r<tl)
	{
		return 127;
	}
	if(tl<=l&&r<=tr)
	{
		return tree[c].s?tree[c].c:'\0';
	}
	int mid=l+(r-l)/2;
	push_down(c,l,r,mid);
	char t1=gl(l,mid,tl,tr,c*2);
	char t2=gl(mid+1,r,tl,tr,c*2+1);
	if(t1=='\0'||t2=='\0')
	{
		return '\0';
	}
	if(t1==t2||t1==127||t2==127) return t1;
	return '\0';
}
char gh(int p)
{
	int gl=1,gr=n,c=1;
	while(gl!=gr)
	{
		int mid=gl+(gr-gl)/2;
		push_down(c,gl,gr,mid);		
		if(p<=mid)
		{
			gr=mid;
			c=c*2;
		}
		else
		{
			gl=mid+1;
			c=c*2+1;
		}
		
	}
	return tree[c].c;
}
bool cjc(int l,int r)
{
	if(l==1||r==n)
	{
		return 1;
	}
	return gh(l-1)!=gh(r+1);
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	build(1,n,1);
	int T;
	scanf("%d",&T);
	while(T--)
	{
		char ff[4];
		int x,y;
		scanf("%s",ff);
		if(ff[0]=='A')
		{
			scanf("%d%d%s",&x,&y,ff);
			change(1,n,x,y,1,ff[0]);
		}
		else
		{
			scanf("%d%d",&x,&y);
			if(gl(1,n,x,y,1)!='\0'&&(cjc(x,y)))
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
//		for(int i=1;i<=n;++i)
//		{
//			putchar(gh(i));
//		}
//		putchar('\n');
	}
	return 0;
}

回复

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

正在加载回复...