话说这题Old Driver Tree 被卡了啊
查看原帖
话说这题Old Driver Tree 被卡了啊
575655
Chtholly_is_cute楼主2023/7/4 22:14

rt,第10个点TLE

code:

#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;

const ll mod = 1000000007;
const ll maxn = 100055;

struct node {
	ll l, r;
	mutable int v;
	node(ll L, ll R = 0, int V = 0) : l(L), r(R), v(V) {}
	bool operator<(const node& a)const {
		return l < a.l;
	}
};

set<node>odt;

int n;

set<node>::iterator split(int pos) {
	auto it = prev(odt.upper_bound(node(pos)));
	if (it->l == pos)return it;
	int l = it->l, r = it->r, v = it->v;
	odt.erase(it);
	odt.insert(node(l, pos - 1, v));
	return odt.insert(node(pos, r, v)).first;
}
void add(ll l, ll r, ll x) {
	set<node>::iterator itr = split(r + 1), itl = split(l);
	for (register set<node>::iterator it = itl; it != itr; it++)it->v += x;
}
void assign(ll l, ll r, ll x) {
	set<node>::iterator Itr = prev(odt.upper_bound(node(r))), Itl = prev(odt.upper_bound(node(l)));
	if (Itr != prev(odt.end()) && Itr->r == r && x == (Itr = next(Itr))->v)r = Itr->r, Itr = next(Itr);
	else if (Itr->v != x)Itr = split(r + 1), Itl = prev(odt.upper_bound(node(l)));
	else r = Itr->r, Itr = next(Itr);

	if (Itl != odt.begin() && Itl->l == l && x == (prev(Itl))->v)Itl = prev(Itl), l = Itl->l;
	if (Itl->v != x)Itl = split(l);
	else l = Itl->l;
	odt.erase(Itl, Itr);
	odt.insert(node(l, r, x));
}
bool query(int l, int r) {
	auto it = prev(odt.upper_bound(node(l)));
	if (it != prev(odt.upper_bound(node(r))))return 0;
	if (!(l != 1 && r != n))return 1;

	if (l > it->l && r < it->r)return 0;
	if (l == it->l && r != it->r)return prev(it)->v != it->v;
	if (r == it->r && l != it->l)return next(it)->v != it->v;
	return prev(it)->v != next(it)->v;
}
char delilegalchar () {
	char o; while ((o = getchar()) < 'A' || o > 'Z'); return o;
}
signed main() {
	cin >> n;
	int l = 1, r = 1, pos = n;
	char w, prcw = delilegalchar();
	while (pos-- > 1) {
		w = delilegalchar(); if (w == prcw) {
			r++;
			continue;
		}
		odt.insert(node(l, r, prcw));
		l = ++r;
		prcw = w;
	}
	odt.insert(node(l, r, prcw));
	int que;
	char o;
	cin >> que;
	do {
		o = delilegalchar();
		cin >> l >> r;
		if (o == 'A')assign(l, r, delilegalchar());
		else {
			if (query(l, r))cout << "Yes";
			else cout << "No";
			cout << endl;
		}
	} while (--que);
}
2023/7/4 22:14
加载中...