Submission #1038583

# Submission time Handle Problem Language Result Execution time Memory
1038583 2024-07-30T02:27:05 Z vjudge1 Global Warming (CEOI18_glo) C++14
48 / 100
249 ms 5212 KB
#include <bits/stdc++.h>

using namespace std;

int n, x;

int a[200005];

int o[200005];

int st[200005];

void upd(int i, int v) {
	
	int l = 1, r = n, id = 1;
	
	while (l < r) {
		int mid = (l + r) / 2;
		id *= 2;
		
		if (i <= mid) {
			r = mid;
		} else {
			l = mid + 1;
			id++;
		}
		
	}
	
	st[id] = max(st[id], v);
	
	while (id > 1) {
		
		id /= 2;
		st[id] = max(st[id * 2], st[id * 2 + 1]);
		
	}
}

int get(int i, int j, int id = 1, int l = 1, int r = n) {
	
	if (i > j) {
		return 0;
	}
	
	if (i <= l && r <= j) {
		return st[id];
	}
	
	int mid = (l + r) / 2;
	
	if (i <= mid && mid < j) {
		return max(get(i, j, id * 2, l, mid), get(i, j, id * 2 + 1, mid + 1, r));
	}
	
	if (mid < i) {
		return get(i, j, id * 2 + 1, mid + 1, r);
	}
	
	return get(i, j, id * 2, l, mid);
}

int lis_l[200005], lis_r[200005];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x;
	
	vector<int> val;
	
	for (int i = 1; i <= n; ++i) {
		
		cin >> a[i];
		
		val.emplace_back(a[i]);
	}
	
	sort(val.begin(), val.end());
	
	val.erase(unique(val.begin(), val.end()), val.end());
	
	for (int i = 1; i <= n; ++i) {
		
		o[i] = lower_bound(val.begin(), val.end(), a[i]) - val.begin() + 1;
		
	}
	
	memset(st, 0, sizeof st);
	
	for (int i = 1; i <= n; ++i) {
		
		lis_l[i] = get(1, o[i] - 1) + 1;
		
		upd(o[i], lis_l[i]);
	}
	
	memset(st, 0, sizeof st);
	
	for (int i = n; i >= 1; --i) {
		
		lis_r[i] = get(o[i] + 1, n) + 1;
		
		upd(o[i], lis_r[i]);
		
	}
	
	memset(st, 0, sizeof st);
	
	int ans = 0;
	
	for (int i = 1; i <= n; ++i) {
		
		int j = upper_bound(val.begin(), val.end(), a[i] + x - 1) - val.begin();
		
		ans = max(ans, get(1, j) + lis_r[i]);
		
		upd(o[i], lis_l[i]);
	}
	
	memset(st, 0, sizeof st);
	
	for (int i = n; i >= 1; --i) {
		
		int j = lower_bound(val.begin(), val.end(), a[i] - x + 1) - val.begin() + 1;
		
		ans = max(ans, get(j, n) + lis_l[i]);
		
		upd(o[i], lis_r[i]);
	}
		
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1164 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1164 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1160 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1164 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1160 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 249 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 2260 KB Output is correct
2 Correct 64 ms 2336 KB Output is correct
3 Correct 63 ms 2168 KB Output is correct
4 Correct 31 ms 2272 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 34 ms 2156 KB Output is correct
7 Correct 53 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 3284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1164 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1160 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1288 KB Output is correct
27 Incorrect 249 ms 5212 KB Output isn't correct
28 Halted 0 ms 0 KB -