16pts
查看原帖
16pts
575655
Chtholly_is_cute楼主2025/2/1 19:00

Old driver tree做法

#include<climits>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
#define int long long
const ll mod = 1000000007;
const ll maxn = 100055;
struct node {
	ll l, r;
	mutable char v;
	node(ll L, ll R = 0, char V = 0) : l(L), r(R), v(V) {}
	bool operator<(const node& a)const {
		return l < a.l;
	}
};
ll n, m, seed, vmax, a[maxn];
set<node>odt;
set<node>::iterator split(int pos) {
	set<node>::iterator it = odt.lower_bound(node(pos));
	if (it != odt.end() && it->l == pos)return it;
	it--;
	if (it->r < pos)return odt.end();
	ll l = it->l;
	ll r = it->r;
	ll v = it->v;
	odt.erase(it);
	odt.insert(node(l, pos - 1, v));
	return odt.insert(node(pos, r, v)).first;
}
void assign(ll l, ll r, ll x) {
	set<node>::iterator itr = split(r + 1), itl = split(l);
	odt.erase(itl, itr);
	odt.insert(node(l, r, x));
}
signed main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	string t;
	t+=s[0];
	for(int i=1;i<n;i++){
		if(s[i-1]==s[i])t+=s[i];
		else{
			odt.insert(node(i-t.size(),i-1,t[0]));
			t="";
			t+=s[i];
		}
	}
	odt.insert(node(n-t.size(),n-1,t[0]));
	if(odt.size()==1){
		if(odt.begin()->v=='0'){
			cout<<0<<endl;
			return 0;
		}
		cout<<(odt.begin()->r - odt.begin()->l+1+1)%2+1;
		return 0;
	}
	set<node>::iterator it;
	int mindays=INT_MAX;
	it=odt.begin();
	if(it->v=='1'){
		mindays=min(mindays,it->r - it->l);
	}
	it=prev(odt.end());
	if(it->v=='1'){
		mindays=min(mindays,it->r - it->l);
	}
	for(it=next(odt.begin());it!=prev(odt.end());it++){
		if(it->v=='1'){
			mindays=min(mindays,(long long)ceil(double(it->r - it->l + 1)/2.00)-1);
		}
	}
	int ans=0;
	for(it=odt.begin();it!=odt.end();++it){
		ans+=ceil(double(it->r - it->l + 1) / (2.00*double(mindays)+1.00));
	}cout<<ans<<endl;
}
2025/2/1 19:00
加载中...