Submission #138115

# Submission time Handle Problem Language Result Execution time Memory
138115 2019-07-29T11:30:23 Z sebinkim Triple Jump (JOI19_jumps) C++14
100 / 100
1069 ms 91240 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

struct node{
	int lv, rv, mv;
	
	node() : lv(-1e9), rv(-1e9), mv(-1e9) {}
	node(int lv, int rv) : lv(lv), rv(rv), mv(-1e9) {}
	
	node operator + (node &n)
	{
		node ret;
		
		ret.lv = max(lv, n.lv);
		ret.rv = max(rv, n.rv);
		ret.mv = max(max(mv, n.mv), lv + n.rv);
		
		return ret;
	}
};

struct segtree{
	node T[1101010];
	int sz = 1 << 19;
	
	void init(int n, int *X)
	{
		int i;
		
		for(i=1; i<=n; i++){
			T[sz + i] = node(-1e9, X[i]);
		}
		
		for(i=sz-1; i; i--){
			T[i] = T[i << 1] + T[i << 1 | 1];
		}
	}
	
	void update(int p, int v)
	{
		p += sz;
		
		if(T[p].lv >= v) return;
		T[p] = node(v, T[p].rv);
		
		for(p>>=1; p; p>>=1){
			T[p] = T[p << 1] + T[p << 1 | 1];
		}
	}
	
	int getval(int l, int r)
	{
		node lv, rv;
		
		l += sz; r += sz;
		
		for(; l<=r; ){
			if(l & 1) lv = lv + T[l];
			if(~r & 1) rv = T[r] + rv;
			l = l + 1 >> 1;
			r = r - 1 >> 1;
		}
		
		return (lv + rv).mv;
	}
};

segtree T;
vector <pii> V[505050], Q[505050];
vector <int> S;
int X[505050], A[505050];
int n;

int main()
{
	int q, i, j, t, l, r;
	
	scanf("%d", &n);
	
	for(i=1; i<=n; i++){
		scanf("%d", X + i);
		for(; !S.empty(); S.pop_back()){
			j = S.back(); t = i + i - j - 1;
			if(t <= n) V[j].emplace_back(t, X[j] + X[i]);
			if(X[j] > X[i]) break;
		}
		S.push_back(i);
	}
	
	T.init(n, X);
	
	scanf("%d", &q);
	
	for(i=1; i<=q; i++){
		scanf("%d%d", &l, &r);
		Q[l].emplace_back(r, i);
	}
	
	for(i=n; i>=1; i--){
		for(pii &t: V[i]){
			T.update(t.first, t.second);
		}
		
		for(pii &q: Q[i]){
			A[q.second] = T.getval(i, q.first);
		}
	}
	
	for(i=1; i<=q; i++){
		printf("%d\n", A[i]);
	}
	
	return 0;
}

Compilation message

jumps.cpp: In member function 'int segtree::getval(int, int)':
jumps.cpp:63:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    l = l + 1 >> 1;
        ~~^~~
jumps.cpp:64:10: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
    r = r - 1 >> 1;
        ~~^~~
jumps.cpp: In function 'int main()':
jumps.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
jumps.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", X + i);
   ~~~~~^~~~~~~~~~~~~
jumps.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
jumps.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 36984 KB Output is correct
2 Correct 38 ms 36984 KB Output is correct
3 Correct 38 ms 36956 KB Output is correct
4 Correct 38 ms 36956 KB Output is correct
5 Correct 38 ms 36980 KB Output is correct
6 Correct 38 ms 36984 KB Output is correct
7 Correct 39 ms 36984 KB Output is correct
8 Correct 43 ms 37020 KB Output is correct
9 Correct 47 ms 36968 KB Output is correct
10 Correct 38 ms 36984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 36984 KB Output is correct
2 Correct 38 ms 36984 KB Output is correct
3 Correct 38 ms 36956 KB Output is correct
4 Correct 38 ms 36956 KB Output is correct
5 Correct 38 ms 36980 KB Output is correct
6 Correct 38 ms 36984 KB Output is correct
7 Correct 39 ms 36984 KB Output is correct
8 Correct 43 ms 37020 KB Output is correct
9 Correct 47 ms 36968 KB Output is correct
10 Correct 38 ms 36984 KB Output is correct
11 Correct 303 ms 55240 KB Output is correct
12 Correct 287 ms 55244 KB Output is correct
13 Correct 285 ms 55288 KB Output is correct
14 Correct 298 ms 55380 KB Output is correct
15 Correct 318 ms 55328 KB Output is correct
16 Correct 333 ms 54572 KB Output is correct
17 Correct 311 ms 54660 KB Output is correct
18 Correct 303 ms 54520 KB Output is correct
19 Correct 321 ms 55112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 45308 KB Output is correct
2 Correct 108 ms 45796 KB Output is correct
3 Correct 128 ms 46512 KB Output is correct
4 Correct 171 ms 47024 KB Output is correct
5 Correct 168 ms 46968 KB Output is correct
6 Correct 174 ms 46252 KB Output is correct
7 Correct 157 ms 46328 KB Output is correct
8 Correct 156 ms 46176 KB Output is correct
9 Correct 162 ms 46564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 36984 KB Output is correct
2 Correct 38 ms 36984 KB Output is correct
3 Correct 38 ms 36956 KB Output is correct
4 Correct 38 ms 36956 KB Output is correct
5 Correct 38 ms 36980 KB Output is correct
6 Correct 38 ms 36984 KB Output is correct
7 Correct 39 ms 36984 KB Output is correct
8 Correct 43 ms 37020 KB Output is correct
9 Correct 47 ms 36968 KB Output is correct
10 Correct 38 ms 36984 KB Output is correct
11 Correct 303 ms 55240 KB Output is correct
12 Correct 287 ms 55244 KB Output is correct
13 Correct 285 ms 55288 KB Output is correct
14 Correct 298 ms 55380 KB Output is correct
15 Correct 318 ms 55328 KB Output is correct
16 Correct 333 ms 54572 KB Output is correct
17 Correct 311 ms 54660 KB Output is correct
18 Correct 303 ms 54520 KB Output is correct
19 Correct 321 ms 55112 KB Output is correct
20 Correct 181 ms 45308 KB Output is correct
21 Correct 108 ms 45796 KB Output is correct
22 Correct 128 ms 46512 KB Output is correct
23 Correct 171 ms 47024 KB Output is correct
24 Correct 168 ms 46968 KB Output is correct
25 Correct 174 ms 46252 KB Output is correct
26 Correct 157 ms 46328 KB Output is correct
27 Correct 156 ms 46176 KB Output is correct
28 Correct 162 ms 46564 KB Output is correct
29 Correct 1069 ms 85604 KB Output is correct
30 Correct 730 ms 82392 KB Output is correct
31 Correct 743 ms 84400 KB Output is correct
32 Correct 971 ms 85524 KB Output is correct
33 Correct 932 ms 85520 KB Output is correct
34 Correct 895 ms 83232 KB Output is correct
35 Correct 889 ms 82868 KB Output is correct
36 Correct 897 ms 82960 KB Output is correct
37 Correct 1022 ms 84324 KB Output is correct
38 Correct 656 ms 91176 KB Output is correct
39 Correct 629 ms 91240 KB Output is correct
40 Correct 602 ms 87768 KB Output is correct
41 Correct 595 ms 87408 KB Output is correct
42 Correct 595 ms 87376 KB Output is correct
43 Correct 602 ms 89100 KB Output is correct
44 Correct 679 ms 90552 KB Output is correct
45 Correct 665 ms 90564 KB Output is correct
46 Correct 727 ms 87500 KB Output is correct
47 Correct 707 ms 86948 KB Output is correct
48 Correct 636 ms 87048 KB Output is correct
49 Correct 644 ms 89248 KB Output is correct
50 Correct 739 ms 88824 KB Output is correct
51 Correct 752 ms 88756 KB Output is correct
52 Correct 713 ms 86392 KB Output is correct
53 Correct 709 ms 85908 KB Output is correct
54 Correct 759 ms 85988 KB Output is correct
55 Correct 740 ms 87592 KB Output is correct