답안 #1027909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027909 2024-07-19T11:25:24 Z Unforgettablepl Mizuyokan 2 (JOI23_mizuyokan2) C++17
0 / 100
4000 ms 4696 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long

struct segtree{
	vector<int> tree;
	segtree():tree(524288){}
	void update(int k,int x){
		k+=262144;
		tree[k]=x;
		while(k/=2){
			tree[k]=max(tree[2*k],tree[2*k+1]);
		}
	}
	int get(int l,int r){
		l+=262144;r+=262144;
		int ans = 0;
		while(l<=r){
			if(l&1)ans=max(ans,tree[l++]);
			if(r%2==0)ans=max(ans,tree[r--]);
			l/=2;r/=2;
		}
		return ans;
	}
};

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();
	vector<int> DP(n+1);
	segtree seg;
	for(int i=1;i<=n;i++){
		while(iter!=buffer.end() and iter->first<S[i-1]){
			seg.update(iter->second,DP[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;
		}
		DP[i]=1;
		if(r==0)continue;
		DP[i]=max(DP[i],seg.get(0,r-1)+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);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4057 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4057 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4057 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4098 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4059 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4057 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -