Submission #766531

# Submission time Handle Problem Language Result Execution time Memory
766531 2023-06-25T18:59:12 Z Tob Global Warming (CEOI18_glo) C++14
100 / 100
447 ms 141536 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")

#define UI unsigned int
#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef pair <ll, ll> pii;

const int N = 2e5 + 7;
const UI ofs = (1 << 31);

UI n, x, cnt=1, pos, xx;
UI a[N], dp[N], dp2[N];

struct node {
	UI lo, hi, le, ri, val;
} t[35*N];

void Update(int x = 1) {
	UI mid = ((ll)t[x].lo + (ll)t[x].hi) / 2;
	if (t[x].hi == t[x].lo) {
		t[x].val = max(t[x].val, xx);
		return;
	}
	if (pos <= mid) {
		if (!t[x].le) {
			t[x].le = ++cnt;
			t[cnt].lo = t[x].lo;
			t[cnt].hi = mid;
		}
		Update(t[x].le);
	}
	else {
		if (!t[x].ri) {
			t[x].ri = ++cnt;
			t[cnt].lo = mid+1;
			t[cnt].hi = t[x].hi;
		}
		Update(t[x].ri);
	}
	t[x].val = max(t[t[x].le].val, t[t[x].ri].val);
}

UI Query(int x = 1) {
	if (x == 0) return 0;
	if (t[x].hi < pos || xx < t[x].lo) return 0;
	if (pos <= t[x].lo && t[x].hi <= xx) return t[x].val;
	return max(Query(t[x].le), Query(t[x].ri));
}

int main () {
	FIO;
	cin >> n >> x;
	
	t[1].lo = 0;
	t[1].hi = ofs-1;
	
	for (UI i = 1; i <= n; i++) {
		cin >> a[i];
		pos = 1; xx = a[i]-1;
		dp[i] = Query() + 1;
		pos = a[i];
		xx = dp[i];
		Update();
	}
	
	memset(t, 0, sizeof t);
	
	t[1].lo = 0;
	t[1].hi = ofs-1;
	cnt = 1;
	
	UI mx = 0;
	for (int i = n; i; i--) {
		pos = a[i]+x+1; xx = ofs-1;
		dp2[i] = Query() + 1;
		pos = a[i]+1;
		mx = max(mx, dp[i] + Query());
		pos = a[i]+x;
		xx = dp2[i];
		Update();
	}
	
	cout << mx;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 137256 KB Output is correct
2 Correct 42 ms 137276 KB Output is correct
3 Correct 41 ms 137228 KB Output is correct
4 Correct 43 ms 137248 KB Output is correct
5 Correct 43 ms 137200 KB Output is correct
6 Correct 42 ms 137244 KB Output is correct
7 Correct 43 ms 137304 KB Output is correct
8 Correct 44 ms 137300 KB Output is correct
9 Correct 43 ms 137268 KB Output is correct
10 Correct 42 ms 137288 KB Output is correct
11 Correct 43 ms 137296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 137256 KB Output is correct
2 Correct 42 ms 137276 KB Output is correct
3 Correct 41 ms 137228 KB Output is correct
4 Correct 43 ms 137248 KB Output is correct
5 Correct 43 ms 137200 KB Output is correct
6 Correct 42 ms 137244 KB Output is correct
7 Correct 43 ms 137304 KB Output is correct
8 Correct 44 ms 137300 KB Output is correct
9 Correct 43 ms 137268 KB Output is correct
10 Correct 42 ms 137288 KB Output is correct
11 Correct 43 ms 137296 KB Output is correct
12 Correct 43 ms 137292 KB Output is correct
13 Correct 43 ms 137204 KB Output is correct
14 Correct 45 ms 137288 KB Output is correct
15 Correct 43 ms 137300 KB Output is correct
16 Correct 46 ms 137296 KB Output is correct
17 Correct 42 ms 137292 KB Output is correct
18 Correct 42 ms 137272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 137256 KB Output is correct
2 Correct 42 ms 137276 KB Output is correct
3 Correct 41 ms 137228 KB Output is correct
4 Correct 43 ms 137248 KB Output is correct
5 Correct 43 ms 137200 KB Output is correct
6 Correct 42 ms 137244 KB Output is correct
7 Correct 43 ms 137304 KB Output is correct
8 Correct 44 ms 137300 KB Output is correct
9 Correct 43 ms 137268 KB Output is correct
10 Correct 42 ms 137288 KB Output is correct
11 Correct 43 ms 137296 KB Output is correct
12 Correct 43 ms 137292 KB Output is correct
13 Correct 43 ms 137204 KB Output is correct
14 Correct 45 ms 137288 KB Output is correct
15 Correct 43 ms 137300 KB Output is correct
16 Correct 46 ms 137296 KB Output is correct
17 Correct 42 ms 137292 KB Output is correct
18 Correct 42 ms 137272 KB Output is correct
19 Correct 44 ms 137292 KB Output is correct
20 Correct 43 ms 137292 KB Output is correct
21 Correct 44 ms 137228 KB Output is correct
22 Correct 42 ms 137224 KB Output is correct
23 Correct 47 ms 137388 KB Output is correct
24 Correct 44 ms 137308 KB Output is correct
25 Correct 44 ms 137208 KB Output is correct
26 Correct 44 ms 137240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 141348 KB Output is correct
2 Correct 441 ms 141536 KB Output is correct
3 Correct 441 ms 141448 KB Output is correct
4 Correct 433 ms 141520 KB Output is correct
5 Correct 261 ms 140876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 138052 KB Output is correct
2 Correct 125 ms 138296 KB Output is correct
3 Correct 122 ms 138268 KB Output is correct
4 Correct 101 ms 138336 KB Output is correct
5 Correct 43 ms 137292 KB Output is correct
6 Correct 96 ms 138176 KB Output is correct
7 Correct 107 ms 138368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 139124 KB Output is correct
2 Correct 245 ms 139384 KB Output is correct
3 Correct 408 ms 141492 KB Output is correct
4 Correct 244 ms 140812 KB Output is correct
5 Correct 141 ms 138956 KB Output is correct
6 Correct 208 ms 140612 KB Output is correct
7 Correct 228 ms 141352 KB Output is correct
8 Correct 165 ms 139444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 137256 KB Output is correct
2 Correct 42 ms 137276 KB Output is correct
3 Correct 41 ms 137228 KB Output is correct
4 Correct 43 ms 137248 KB Output is correct
5 Correct 43 ms 137200 KB Output is correct
6 Correct 42 ms 137244 KB Output is correct
7 Correct 43 ms 137304 KB Output is correct
8 Correct 44 ms 137300 KB Output is correct
9 Correct 43 ms 137268 KB Output is correct
10 Correct 42 ms 137288 KB Output is correct
11 Correct 43 ms 137296 KB Output is correct
12 Correct 43 ms 137292 KB Output is correct
13 Correct 43 ms 137204 KB Output is correct
14 Correct 45 ms 137288 KB Output is correct
15 Correct 43 ms 137300 KB Output is correct
16 Correct 46 ms 137296 KB Output is correct
17 Correct 42 ms 137292 KB Output is correct
18 Correct 42 ms 137272 KB Output is correct
19 Correct 44 ms 137292 KB Output is correct
20 Correct 43 ms 137292 KB Output is correct
21 Correct 44 ms 137228 KB Output is correct
22 Correct 42 ms 137224 KB Output is correct
23 Correct 47 ms 137388 KB Output is correct
24 Correct 44 ms 137308 KB Output is correct
25 Correct 44 ms 137208 KB Output is correct
26 Correct 44 ms 137240 KB Output is correct
27 Correct 424 ms 141348 KB Output is correct
28 Correct 441 ms 141536 KB Output is correct
29 Correct 441 ms 141448 KB Output is correct
30 Correct 433 ms 141520 KB Output is correct
31 Correct 261 ms 140876 KB Output is correct
32 Correct 122 ms 138052 KB Output is correct
33 Correct 125 ms 138296 KB Output is correct
34 Correct 122 ms 138268 KB Output is correct
35 Correct 101 ms 138336 KB Output is correct
36 Correct 43 ms 137292 KB Output is correct
37 Correct 96 ms 138176 KB Output is correct
38 Correct 107 ms 138368 KB Output is correct
39 Correct 207 ms 139124 KB Output is correct
40 Correct 245 ms 139384 KB Output is correct
41 Correct 408 ms 141492 KB Output is correct
42 Correct 244 ms 140812 KB Output is correct
43 Correct 141 ms 138956 KB Output is correct
44 Correct 208 ms 140612 KB Output is correct
45 Correct 228 ms 141352 KB Output is correct
46 Correct 165 ms 139444 KB Output is correct
47 Correct 216 ms 139328 KB Output is correct
48 Correct 223 ms 139444 KB Output is correct
49 Correct 447 ms 141496 KB Output is correct
50 Correct 263 ms 140800 KB Output is correct
51 Correct 189 ms 139916 KB Output is correct
52 Correct 256 ms 140876 KB Output is correct
53 Correct 216 ms 140828 KB Output is correct
54 Correct 220 ms 141520 KB Output is correct
55 Correct 320 ms 141484 KB Output is correct