제출 #781186

#제출 시각아이디문제언어결과실행 시간메모리
781186AdamGSMizuyokan 2 (JOI23_mizuyokan2)C++17
6 / 100
3624 ms7356 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=207;
int dp[LIM][LIM][2];
ll sum[LIM];
ll cnt(int l, int r) {
	return sum[r]-(l?sum[l-1]:0);
}
int solve(vector<ll>T) {
	int n=T.size();
	rep(i, n) {
		sum[i]=T[i];
		if(i) sum[i]+=sum[i-1];
	}
	rep(i, n) rep(j, n) rep(l, 2) dp[i][j][l]=-INF;
	rep(r, n) rep(l, r+1) {
		if(l==0) {
			dp[l][r][0]=dp[l][r][1]=1;
			continue;
		}
		rep(i, l) {
			if(cnt(i, l-1)>cnt(l, r)) dp[l][r][0]=max(dp[l][r][0], dp[i][l-1][1]+1);
			else if(cnt(i, l-1)<cnt(l, r)) dp[l][r][1]=max(dp[l][r][1], dp[i][l-1][0]+1);
		}
	}
	int ans=0;
	rep(i, n) rep(j, 2) ans=max(ans, dp[i][n-1][j]);
	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...