Submission #1027903

# Submission time Handle Problem Language Result Execution time Memory
1027903 2024-07-19T11:19:11 Z Unforgettablepl Mizuyokan 2 (JOI23_mizuyokan2) C++17
0 / 100
325 ms 2312 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
void answer(vector<int> arr){
	int n = arr.size();
	arr.insert(arr.begin(),0);
	vector<int> S(n+1);
	for(int i=1;i<=n;i++)S[i]=S[i-1]+arr[i];
	vector<pair<int,int>> buffer(n+1);
	for(int i=1;i<=n;i++)buffer[i]={arr[i]+S[i],i};
	sort(buffer.begin(),buffer.end());
	auto iter = buffer.begin();
	set<int> possible;
	vector<int> DP(n+1);
	for(int i=1;i<=n;i++){
		while(iter!=buffer.end() and iter->first<S[i-1]){
			possible.insert((iter++)->second);
		}
		int r = i-1;
		for(int jump=131072;jump;jump/=2){
			if(r-jump<0)continue;
			if(S[r-jump]>=S[i-1]-arr[i])r-=jump;
		}
		auto iter2 = possible.lower_bound(r);
		DP[i]=1;
		if(iter2==possible.begin())continue;
		iter2--;
		int j = *iter2;
		DP[i]=max(DP[i],DP[j]+2);
	}
	int ans = DP[n];
	int sum = arr[n];
	for(int i=n-1;i;i--){
		if(arr[i]<sum)ans=max(ans,DP[i]+1);
		sum+=arr[i];
	}
	cout << ans << '\n';
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> L(n+1);
	for(int i=1;i<=n;i++)cin>>L[i];
	int q;
	cin >> q;
	for(int i=1;i<=q;i++){
		int x,y,a,b;cin>>x>>y>>a>>b;
		L[x]=y;
		vector<int> arr;
		for(int j=a+1;j<=b;j++){
			arr.emplace_back(L[j]);
		}
		answer(arr);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 325 ms 2064 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 315 ms 2312 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -