답안 #140195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140195 2019-08-02T08:48:52 Z arman_ferdous 3단 점프 (JOI19_jumps) C++11
100 / 100
1397 ms 134264 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int N = 5e5+10;
const ll oo = 1e18;

int n;
ll a[N];
deque<pair<int,int>>q;
vector<pair<int,int>> rel;

struct data{
	ll ab, c, sum;
	data(ll x = -oo,ll y = -oo, ll z = -oo) {
		ab = x, c = y, sum = z;
	}
}t[N<<2];

data merge(data L, data R) {
	return data({max(L.ab, R.ab), max(L.c, R.c), max({L.sum, R.sum, L.ab + R.c})});
}

void updAB(int node, int L, int R, int pos, ll x) {
	if(L == R) {
		t[node].ab = max(t[node].ab, x);
		t[node].sum = t[node].ab + t[node].c;
		return;
	} int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;
	if(pos <= mid) updAB(lc, L, mid, pos, x);
	else updAB(rc, mid + 1, R, pos, x);
	t[node] = merge(t[lc], t[rc]);
}

void updC(int node, int L, int R, int pos, ll x) {
	if(L == R) {
		t[node].c = x;
		t[node].sum = t[node].ab + t[node].c;
		return;
	} int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;
	if(pos <= mid) updC(lc, L, mid, pos, x);
	else updC(rc, mid + 1, R, pos, x);
	t[node] = merge(t[lc], t[rc]);
}

data get(int node, int L, int R, int l, int r) {
	if(r < L || R < l) return data();
	if(l <= L && R <= r) return t[node];
	int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;
	data le = get(lc, L, mid, l, r);
	data ri = get(rc, mid + 1, R, l, r);
	return merge(le, ri);
}

vector<pair<int,int>> off[N];
vector<int> candi[N];
ll ans[N];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	q.push_back({INT_MAX, -1});
	for(int i = 1; i <= n; i++) {
		while(q.back().first < a[i]) {
			rel.push_back({q.back().second, i});
			q.pop_back();
		}
		if(q.back().second + 1) rel.push_back({q.back().second, i});
		q.push_back({a[i], i});
	}
	for(auto it : rel) candi[it.first].push_back(it.second);

	int m; scanf("%d", &m);
	for(int i = 0; i < m; i++) {
		int l, r; scanf("%d %d", &l, &r);
		off[l].push_back({r, i});
	}
	for(int i = n; i > 0; i--) {
		updC(1, 1, n, i, a[i]);
		for(auto it : candi[i]) if(2 * it - i <= n) updAB(1, 1, n, 2 * it - i, a[i] + a[it]);
		for(auto qu : off[i]) ans[qu.second] = get(1, 1, n, i, qu.first).sum;
	}
	for(int i = 0; i < m; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
jumps.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
jumps.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int m; scanf("%d", &m);
         ~~~~~^~~~~~~~~~
jumps.cpp:76:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int l, r; scanf("%d %d", &l, &r);
             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 70776 KB Output is correct
2 Correct 62 ms 70776 KB Output is correct
3 Correct 61 ms 70904 KB Output is correct
4 Correct 61 ms 70776 KB Output is correct
5 Correct 62 ms 70728 KB Output is correct
6 Correct 62 ms 70776 KB Output is correct
7 Correct 62 ms 70840 KB Output is correct
8 Correct 62 ms 70776 KB Output is correct
9 Correct 61 ms 70776 KB Output is correct
10 Correct 61 ms 70780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 70776 KB Output is correct
2 Correct 62 ms 70776 KB Output is correct
3 Correct 61 ms 70904 KB Output is correct
4 Correct 61 ms 70776 KB Output is correct
5 Correct 62 ms 70728 KB Output is correct
6 Correct 62 ms 70776 KB Output is correct
7 Correct 62 ms 70840 KB Output is correct
8 Correct 62 ms 70776 KB Output is correct
9 Correct 61 ms 70776 KB Output is correct
10 Correct 61 ms 70780 KB Output is correct
11 Correct 490 ms 91236 KB Output is correct
12 Correct 494 ms 91092 KB Output is correct
13 Correct 490 ms 91060 KB Output is correct
14 Correct 485 ms 91036 KB Output is correct
15 Correct 479 ms 91128 KB Output is correct
16 Correct 483 ms 90448 KB Output is correct
17 Correct 491 ms 90440 KB Output is correct
18 Correct 493 ms 90488 KB Output is correct
19 Correct 479 ms 91000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 83808 KB Output is correct
2 Correct 183 ms 81920 KB Output is correct
3 Correct 187 ms 83612 KB Output is correct
4 Correct 249 ms 83804 KB Output is correct
5 Correct 266 ms 83800 KB Output is correct
6 Correct 259 ms 83144 KB Output is correct
7 Correct 237 ms 82880 KB Output is correct
8 Correct 236 ms 83024 KB Output is correct
9 Correct 241 ms 83264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 70776 KB Output is correct
2 Correct 62 ms 70776 KB Output is correct
3 Correct 61 ms 70904 KB Output is correct
4 Correct 61 ms 70776 KB Output is correct
5 Correct 62 ms 70728 KB Output is correct
6 Correct 62 ms 70776 KB Output is correct
7 Correct 62 ms 70840 KB Output is correct
8 Correct 62 ms 70776 KB Output is correct
9 Correct 61 ms 70776 KB Output is correct
10 Correct 61 ms 70780 KB Output is correct
11 Correct 490 ms 91236 KB Output is correct
12 Correct 494 ms 91092 KB Output is correct
13 Correct 490 ms 91060 KB Output is correct
14 Correct 485 ms 91036 KB Output is correct
15 Correct 479 ms 91128 KB Output is correct
16 Correct 483 ms 90448 KB Output is correct
17 Correct 491 ms 90440 KB Output is correct
18 Correct 493 ms 90488 KB Output is correct
19 Correct 479 ms 91000 KB Output is correct
20 Correct 267 ms 83808 KB Output is correct
21 Correct 183 ms 81920 KB Output is correct
22 Correct 187 ms 83612 KB Output is correct
23 Correct 249 ms 83804 KB Output is correct
24 Correct 266 ms 83800 KB Output is correct
25 Correct 259 ms 83144 KB Output is correct
26 Correct 237 ms 82880 KB Output is correct
27 Correct 236 ms 83024 KB Output is correct
28 Correct 241 ms 83264 KB Output is correct
29 Correct 1394 ms 128612 KB Output is correct
30 Correct 1199 ms 123996 KB Output is correct
31 Correct 1230 ms 128116 KB Output is correct
32 Correct 1393 ms 128596 KB Output is correct
33 Correct 1375 ms 128420 KB Output is correct
34 Correct 1364 ms 126276 KB Output is correct
35 Correct 1364 ms 126208 KB Output is correct
36 Correct 1397 ms 126032 KB Output is correct
37 Correct 1366 ms 127492 KB Output is correct
38 Correct 987 ms 134264 KB Output is correct
39 Correct 985 ms 134228 KB Output is correct
40 Correct 961 ms 130828 KB Output is correct
41 Correct 1010 ms 130472 KB Output is correct
42 Correct 1020 ms 130512 KB Output is correct
43 Correct 1076 ms 132336 KB Output is correct
44 Correct 1144 ms 133688 KB Output is correct
45 Correct 1064 ms 133656 KB Output is correct
46 Correct 1034 ms 130640 KB Output is correct
47 Correct 1033 ms 130136 KB Output is correct
48 Correct 1034 ms 130268 KB Output is correct
49 Correct 1065 ms 132304 KB Output is correct
50 Correct 1160 ms 131928 KB Output is correct
51 Correct 1158 ms 131920 KB Output is correct
52 Correct 1201 ms 129360 KB Output is correct
53 Correct 1131 ms 128976 KB Output is correct
54 Correct 1134 ms 128928 KB Output is correct
55 Correct 1136 ms 130768 KB Output is correct