Submission #781195

#TimeUsernameProblemLanguageResultExecution timeMemory
781195AdamGSMizuyokan 2 (JOI23_mizuyokan2)C++17
28 / 100
4083 ms27332 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e9+7;
const int LIM=25e4+7;
int tr[4*LIM], dp[LIM], N=1;
vector<int>V[LIM];
ll sum[LIM];
ll cnt(int l, int r) {
	return sum[r]-(l?sum[l-1]:0);
}
void upd(int v, int x) {
	v+=N;
	while(v) {
		tr[v]=max(tr[v], x);
		v/=2;
	}
}
int cnt2(int l, int r) {
	if(l>r) return -INF;
	l+=N; r+=N;
	int ans=max(tr[l], tr[r]);
	while(l/2!=r/2) {
		if(l%2==0) ans=max(ans, tr[l+1]);
		if(r%2==1) ans=max(ans, tr[r-1]);
		l/=2; r/=2;
	}
	return ans;
}
int solve(vector<ll>T) {
	int n=T.size();
	rep(i, n+1) V[i].clear();
	rep(i, n) {
		sum[i]=T[i];
		if(i) sum[i]+=sum[i-1];
		dp[i]=-INF;
	}
	N=1;
	while(N<n) N*=2;
	rep(i, 2*N) tr[i]=-INF;
	rep(i, n) {
		for(auto j : V[i]) upd(j, dp[j]);
		if(i==0) dp[i]=1;
		else if(cnt(0, i-1)>T[i]) {
			dp[i]=2;
			int po=0, ko=i-1;
			while(po<ko) {
				int sr=(po+ko+1)/2;
				if(cnt(sr, i-1)>T[i]) po=sr; else ko=sr-1;
			}
			dp[i]=max(dp[i], cnt2(0, po-1)+2);
		}
		if(cnt(i+1, n-1)>T[i]) {
			int po=i+1, ko=n-1;
			while(po<ko) {
				int sr=(po+ko)/2;
				if(cnt(i+1, sr)>T[i]) ko=sr; else po=sr+1;
			}
			V[po+1].pb(i);
		}
	}
	int ans=max(1, dp[n-1]);
	rep(i, n-1) if(cnt(i+1, n-1)>T[i]) ans=max(ans, dp[i]+1);
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<ll>T(n);
	rep(i, n) cin >> T[i];
	int q;
	cin >> q;
	while(q--) {
		ll x, y, a, b;
		cin >> x >> y >> a >> b; --x; --b;
		T[x]=y;
		vector<ll>P;
		while(a<=b) {
			P.pb(T[a]);
			++a;
		}
		cout << solve(P) << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...