Submission #908148

# Submission time Handle Problem Language Result Execution time Memory
908148 2024-01-16T08:36:42 Z arashMLG Triple Jump (JOI19_jumps) C++17
0 / 100
386 ms 113904 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;

const int N = 5e5 + 23;
const ll inf = 1e18;

#define F                  first
#define S                  second
#define pb	               push_back
#define sz(x)              ((int)x.size())
#define kill(x)            cout<<x , exit(0);
#define all(x)             x.begin(),x.end()
#define lc                 (v<<1)
#define rc                 ((v<<1)|1)
#define debug(x)           cerr<< #x << " : " << x << '\n';
#define int               	ll

struct Seg {
	int t[N<<2];
	
	Seg() {
		fill(t,t+(N<<2),0);
	}
	
	void clear() {
		fill(t,t+(N<<2),0);
	}

	void upd(int pos,int x,int v=1,int tl=1,int tr= N) {
		if(tr-tl==1) {
			t[v] = max(t[v],x);
			return;
		}	
		int mid=(tl+tr)/2;
		if(pos<mid)
			upd(pos,x,lc,tl,mid);
		else
			upd(pos,x,rc,mid,tr);
		t[v] = max(t[lc],t[rc]);
	}
	
	int get(int l,int r,int v=1,int tl=1,int tr= N) {
		if(l > r) return 0;
		if(l == tl && r == tr-1) return t[v];
		int mid=(tl + tr)/2;
		return max(get(l,min(mid-1,r),lc,tl,mid) , get(max(l,mid),r,rc,mid,tr));
	}
}seg,mx;

int n,q;
int a[N];
vector<pair<int,int>> Q[N];
vector<pair<int,int>> here[N];
int ans[N];
vector<int> st;
vector<pair<int,int> > edges;

int32_t main() {
	cin>>n;
	for(int i = 1; i<= n ; i ++) {
		cin>>a[i];
		mx.upd(i,a[i]);
	}
	cin>>q;
	st.pb(0);
	for(int i = 1; i<= n ; i++) {
		while(st.back() && a[st.back()] < a[i]) st.pop_back();
		if(sz(st) > 1) {
			edges.pb({st.back(),i});
			if(sz(st) > 2) {
				edges.pb({ st[sz(st)-2],i});
			}
		}
		st.pb(i);
	} st.clear();
	st.pb(0);
	for(int i = n ; i >= 1;i --) {
		while(st.back() && a[st.back()] < a[i]) st.pop_back();
		if(sz(st) > 1) {
			edges.pb({i,st.back()});
			if(sz(st) > 2) {
				edges.pb({i,st[sz(st)-2]});
			}
		}
		st.pb(i);
	}
	for(int i = 1; i< n ; i++) {
		edges.pb({i,n});
	}
	for(int i = 2; i<= n ; i++) {
		edges.pb({1,i});
	}
	for(auto [l,r] : edges) {
		here[l].pb({r,a[l] + a[r] + mx.get(l+1,(l+r)/2)});
	}
	for(int i = 0; i < q; i ++) {
		int l,r; cin>>l>>r;
		Q[l].pb({r,i});	
	}
	for(int i = n; i>= 1;i --) {
		for(auto [r,val] : here[i]) {
			seg.upd(r,val);
		}
		for(auto [r,id]  : Q[i]) ans[id] = seg.get(i,r);
	}
	for(int i = 0 ; i< q; i ++) {
		cout<<ans[i] << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 58968 KB Output is correct
2 Incorrect 13 ms 58716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 58968 KB Output is correct
2 Incorrect 13 ms 58716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 379 ms 112796 KB Output is correct
2 Correct 256 ms 98288 KB Output is correct
3 Correct 276 ms 98284 KB Output is correct
4 Correct 386 ms 113824 KB Output is correct
5 Correct 383 ms 112796 KB Output is correct
6 Correct 371 ms 113820 KB Output is correct
7 Incorrect 374 ms 113904 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 58968 KB Output is correct
2 Incorrect 13 ms 58716 KB Output isn't correct
3 Halted 0 ms 0 KB -