求大佬查错,样例过了,只 AC 了最后一组数据
查看原帖
求大佬查错,样例过了,只 AC 了最后一组数据
396974
Buried_Dream楼主2022/5/21 11:23
/*
	Work by: TLE_Automation
*/
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define int long long
using namespace std;

const int N = 1e6 + 10;
const int MAXN = 5e5 + 10;

inline char readchar() {
	static char buf[100000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read() {
#define readchar getchar
	int res = 0, f = 0;char ch = readchar();
	for(; !isdigit(ch); ch = readchar()) if(ch == '-') f = 1;
	for(; isdigit(ch); ch = readchar()) res = (res << 1) + (res << 3) + (ch ^ '0');
	return f ? -res : res;
}

inline void print(int x) {
	if (x < 0 ) putchar('-'), x = -x;
	if (x > 9 ) print(x / 10);
	putchar(x % 10 + '0');
}

char s[N];

namespace Segment_Tree {
	#define lson rt << 1
	#define rson rt << 1 | 1
	struct _Node { int l, r, col, lazy;} tree[MAXN << 2];
	void build(int rt, int l, int r) {
		tree[rt].l = l, tree[rt].r = r;
		if(l == r) return tree[rt].col = s[l] - 'A', void();
		int mid = (l + r) >> 1; build(lson, l, mid), build(rson, mid + 1, r);
		tree[rt].col = (tree[lson].col == tree[rson].col ? tree[lson].col : -1), tree[rt].lazy = -1;
	}
	void pushdown(int rt) {
		if(tree[rt].lazy == -1) return;
		tree[lson].col = tree[lson].lazy = tree[rson].col = tree[rson].lazy = tree[rt].lazy;
		tree[rt].lazy = -1;
	}
	void change(int rt, int l, int r, char k) {
		if(tree[rt].l > r || tree[rt].r < l) return;
		if(tree[rt].l >= l && tree[rt].r <= r) return tree[rt].col = tree[rt].lazy = (k - 'A'), void();
		pushdown(rt); change(lson, l, r, k), change(rson, l, r, k);
		tree[rt].col = (tree[lson].col == tree[rson].col ? tree[lson].col : -1);
	}
	int Query(int rt, int l, int r) {
		if(tree[rt].l >= l && tree[rt].r <= r) return tree[rt].col;
		int mid = (tree[rt].l + tree[rt].r) >> 1;
		int Res = -2; pushdown(rt);
		if(l <= mid) Res = Query(lson, l, r);
		else if(r >= mid + 1) Res = Query(rson, l, r);
		if(Res != -2) return Res;
	}
}  

using namespace Segment_Tree;
char x;
char sss;

signed main() {
//	freopen("cin.in", "r", std.in);
//	freopen("ans.out", "w", stdout);
	int n = read();
	for(int i = 1; i <= n; i++) cin >> s[i];
	int Q = read();
	build(1, 1, n);
	while(Q--) {
		cin >> x; int l, r;
		if(x == 'A') {
			l = read(), r = read(), cin >> sss, change(1, l, r, sss);
		} 
		else if(x == 'B') {
			l = read(), r = read();
			int res1 = 0, res2 = 0, res3 = 0;
			res3 = Query(1, l, r);	
			if(l != 1 && r != n) {
				res1 = Query(1, l - 1, l - 1);
				res2 = Query(1, r + 1, r + 1);
				if(res3 != -1 && (res1 != res2)) puts("Yes");
				else puts("No");
			}
			else if(l == 1 || r == n) {
				if(res3 != -1) puts("Yes");
				else puts("No");
			}
		}
	}
}
2022/5/21 11:23
加载中...