Submission #943598

# Submission time Handle Problem Language Result Execution time Memory
943598 2024-03-11T16:09:45 Z PlayVoltz Triple Jump (JOI19_jumps) C++17
100 / 100
1238 ms 158132 KB
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

vector<int> vect;

struct node{
	int s, e, m, val, lazy, c, sum;
	node *l, *r;
	void propagate(){
		if (lazy==-1)return;
		val=max(val, lazy);
		sum=max(sum, val+c);
		if (s!=e){
			l->lazy=max(l->lazy, lazy);
			r->lazy=max(r->lazy, lazy);
		}
		lazy=-1;
	}
	node(int S, int E){
		s = S, e = E, m = (s+e)/2;
		val=sum=-1e9;
		lazy=-1;
		if (s!=e){
			l = new node(s, m);
			r = new node(m+1, e);
			c=max(l->c, r->c);
		}
		else c=vect[s];
	}
	void up(int left, int right, int v){
		if (left>right)return;
		propagate();
		if (s==left && e==right)lazy=max(lazy, v);
		else{
			if (right<=m)l->up(left, right, v);
			else if (left>m)r->up(left, right, v);
			else l->up(left, m, v), r->up(m+1, right, v);
			r->propagate(), l->propagate();
			sum=max(l->sum, r->sum);
		}
		
	}
	int query(int left, int right){
		propagate();
		if (s==left && e==right)return sum;
		if (right<=m)return l->query(left, right);
		else if (left>m)return r->query(left, right);
		else return max(l->query(left, m), r->query(m+1, right));
	}
}*st;

int32_t main(){
	int n, q, a, b;
	cin>>n;
	vect.resize(n+1);
	vector<vector<pii> > queries(n+1);
	for (int i=1; i<=n; ++i)cin>>vect[i];
	cin>>q;
	vector<int> ans(q);
	vector<vector<int> > next(n+1);
	st = new node(1, n);
	for (int i=0; i<q; ++i){
		cin>>a>>b;
		queries[a].pb(mp(b, i));
	}
	stack<int> s;
	for (int i=1; i<=n; ++i){
		while (!s.empty()&&vect[s.top()]<=vect[i])next[s.top()].pb(i), s.pop();
		s.push(i);
	}
	while (!s.empty())s.pop();
	for (int i=n; i>=1; --i){
		while (!s.empty()&&vect[s.top()]<=vect[i])next[i].pb(s.top()), s.pop();
		s.push(i);
	}
	for (int i=n; i>=1; --i){
		for (auto c:next[i])st->up(2*c-i, n, vect[i]+vect[c]);
		for (auto c:queries[i])ans[c.se]=st->query(i, c.fi);
	}
	for (auto a:ans)cout<<a<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 285 ms 26196 KB Output is correct
12 Correct 300 ms 26148 KB Output is correct
13 Correct 295 ms 26280 KB Output is correct
14 Correct 307 ms 26532 KB Output is correct
15 Correct 286 ms 26240 KB Output is correct
16 Correct 292 ms 25584 KB Output is correct
17 Correct 323 ms 25936 KB Output is correct
18 Correct 292 ms 25520 KB Output is correct
19 Correct 290 ms 26252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 51412 KB Output is correct
2 Correct 116 ms 50512 KB Output is correct
3 Correct 119 ms 50416 KB Output is correct
4 Correct 182 ms 52560 KB Output is correct
5 Correct 163 ms 52708 KB Output is correct
6 Correct 156 ms 52304 KB Output is correct
7 Correct 171 ms 52172 KB Output is correct
8 Correct 147 ms 52052 KB Output is correct
9 Correct 155 ms 52648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 285 ms 26196 KB Output is correct
12 Correct 300 ms 26148 KB Output is correct
13 Correct 295 ms 26280 KB Output is correct
14 Correct 307 ms 26532 KB Output is correct
15 Correct 286 ms 26240 KB Output is correct
16 Correct 292 ms 25584 KB Output is correct
17 Correct 323 ms 25936 KB Output is correct
18 Correct 292 ms 25520 KB Output is correct
19 Correct 290 ms 26252 KB Output is correct
20 Correct 163 ms 51412 KB Output is correct
21 Correct 116 ms 50512 KB Output is correct
22 Correct 119 ms 50416 KB Output is correct
23 Correct 182 ms 52560 KB Output is correct
24 Correct 163 ms 52708 KB Output is correct
25 Correct 156 ms 52304 KB Output is correct
26 Correct 171 ms 52172 KB Output is correct
27 Correct 147 ms 52052 KB Output is correct
28 Correct 155 ms 52648 KB Output is correct
29 Correct 1187 ms 155560 KB Output is correct
30 Correct 1055 ms 153332 KB Output is correct
31 Correct 1039 ms 149304 KB Output is correct
32 Correct 1162 ms 155472 KB Output is correct
33 Correct 1196 ms 155408 KB Output is correct
34 Correct 1099 ms 154084 KB Output is correct
35 Correct 1238 ms 154028 KB Output is correct
36 Correct 1130 ms 153828 KB Output is correct
37 Correct 1156 ms 154856 KB Output is correct
38 Correct 786 ms 158132 KB Output is correct
39 Correct 820 ms 157988 KB Output is correct
40 Correct 762 ms 155364 KB Output is correct
41 Correct 724 ms 155176 KB Output is correct
42 Correct 717 ms 155472 KB Output is correct
43 Correct 742 ms 156668 KB Output is correct
44 Correct 849 ms 157652 KB Output is correct
45 Correct 834 ms 157812 KB Output is correct
46 Correct 816 ms 155416 KB Output is correct
47 Correct 765 ms 155352 KB Output is correct
48 Correct 767 ms 155328 KB Output is correct
49 Correct 825 ms 156768 KB Output is correct
50 Correct 913 ms 157268 KB Output is correct
51 Correct 921 ms 157168 KB Output is correct
52 Correct 892 ms 155600 KB Output is correct
53 Correct 863 ms 155320 KB Output is correct
54 Correct 879 ms 155372 KB Output is correct
55 Correct 936 ms 156392 KB Output is correct