abc285f求调
  • 板块学术版
  • 楼主Leeqyx
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/27 20:19
  • 上次更新2024/7/27 21:40:22
查看原帖
abc285f求调
1029916
Leeqyx楼主2024/7/27 20:19

题目链接

#include<iostream>
using namespace std;

struct __tree {
//	int l,r;
	int lm,rm;
	bool moy;
	int cnt[27];
} tree[500005];
struct __letters {
	int cnt[27];
	bool moy;
	int lm,rm;
	void init() {
		lm = 0x7fffffff;
		rm = 0;
		for(int i = 1; i <= 26; i++)
			cnt[i] = 0;
		moy = true;
	}
} waeieu;
int n,q,a[10005],cntw[27],x,l,r,mx;
char in;
int pos[100005];

void build(int q,int l,int r) {
	if(l == r) {
//		tree[q].l = l;
//		tree[q].r = r;
		pos[l] = q;
		tree[q].lm = tree[q].rm = a[l];
		tree[q].moy = true;
		tree[q].cnt[a[l]]++;
		mx = max(mx,q);
		return ;
	}
	build(2*q,l,(l+r)/2);
	build(2*q+1,(l+r)/2+1,r);
//	tree[q].l = l;
//	tree[q].r = r;
	tree[q].lm = tree[2*q].lm;
	tree[q].rm = tree[2*q+1].rm;
	if(tree[2*q].moy and tree[2*q+1].moy and tree[2*q].rm <= tree[2*q+1].lm)
		tree[q].moy = true;
	for(int i = 1; i <= 26; i++)
		tree[q].cnt[i] = tree[2*q].cnt[i] + tree[2*q+1].cnt[i];
}

void change(int q,int pos,int l,int r,int mess) {
	if(l > pos or r < pos) return ;
	if(pos == l and pos == r) {
		tree[q].cnt[tree[q].lm]--;
		cntw[tree[q].lm]--;
		tree[q].lm = tree[q].rm = mess;
		cntw[tree[q].lm]++;
		tree[q].cnt[tree[q].lm]++;
		return ;
	}
	if(l <= x and x <=(l+r)/2) {
		change(2*q,x,l,(l+r)/2,mess);
		tree[q].lm = tree[2*q].lm;
	} else {
		change(2*q+1,x,(l+r)/2+1,r,mess);
		tree[q].rm = tree[2*q+1].rm;
	}
	if(tree[2*q].moy and tree[2*q+1].moy and tree[2*q].rm <= tree[2*q+1].lm)
		tree[q].moy = true;
	else tree[q].moy = false;
	for(int i = 1; i <= 26; i++)
		tree[q].cnt[i] = tree[2*q].cnt[i] + tree[2*q+1].cnt[i];
}

bool check(int q,int l,int r,int ln,int rn,__letters &akall,int &fail_mess) {
	if(l > rn or r < ln) return false;
	if(l >= ln and rn >= r) {
		cout<<q<<' '<<l<<' '<<r<<' '<<tree[q].moy<<' ';
		for(int i = 1; i <= 26; i++)
			akall.cnt[i] = akall.cnt[i] + tree[q].cnt[i];
		akall.moy = min(tree[q].moy,akall.moy);
		akall.lm = min(akall.lm,tree[q].lm);
		if(akall.rm > tree[q].lm)
			akall.moy = false;
		akall.rm = tree[q].rm;
		cout<<akall.moy<<'\n';
		return false;
	}
	if(l == r) return true;
	bool k = check(2*q,l,(l+r)/2,ln,rn,waeieu,fail_mess);
	k = check(2*q+1,(l+r)/2+1,r,ln,rn,waeieu,fail_mess);
	if(q != 1) return true;
	if(!waeieu.moy) {
		fail_mess = 1;
		return false;
	}
	if(akall.lm != akall.rm)
		for(int i = akall.lm; i < akall.rm; i++)
			if(akall.cnt[i] != cntw[i]) {
				fail_mess = 2;
				return false;
			}
	return true;
}

int main() {
	freopen("1.in","r",stdin);
	freopen("ans.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>in,a[i] = in - 'a' + 1,cntw[a[i]]++;
	build(1,1,n);
	cin>>q;
	for(int i = 1,op; i <= q; i++) {
		cin>>op;
		if(op == 1) {
			cin>>x>>in;
			a[x] = in;
			change(1,x,1,n,in - 'a' + 1);
		} else {
			int k;
			cin>>l>>r;
			waeieu.init();
			if(check(1,1,n,l,r,waeieu,k)) cout<<"Yes\n";
			else cout<<k<<"No\n";
		}
	}
}
2024/7/27 20:19
加载中...