Submission #570136

# Submission time Handle Problem Language Result Execution time Memory
570136 2022-05-28T18:25:17 Z MarcosPauloEvers Global Warming (CEOI18_glo) C++17
100 / 100
53 ms 4312 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5 + 10;
int n, x;
int arr[MAXN], sz[MAXN];
vector<int> lis;

int
main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> x;

	for(int i = 0; i < n; i++)
		cin >> arr[i];

	for(int i = n - 1; i >= 0; i--)
	{
		int l = 0, r = lis.size() - 1;
		while(l <= r)
		{
			int t = (l + r) >> 1;

			if(lis[t] > arr[i]) l = t + 1;
			else r = t - 1;
		}
	
		if(l == lis.size()) lis.push_back(arr[i]), sz[i] = lis.size();
		else lis[l] = arr[i], sz[i] = l + 1;
	}
	lis.clear();
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		ans = max(ans, sz[i] + int(lower_bound(begin(lis), end(lis), arr[i] + x) - begin(lis)));
	
		auto it = lower_bound(begin(lis), end(lis), arr[i]);

		if(it == end(lis)) lis.push_back(arr[i]);
		else *it = arr[i];
	}

	cout << ans << "\n";
	return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:30:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   if(l == lis.size()) lis.push_back(arr[i]), sz[i] = lis.size();
      |      ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3804 KB Output is correct
2 Correct 49 ms 3796 KB Output is correct
3 Correct 53 ms 3788 KB Output is correct
4 Correct 51 ms 3804 KB Output is correct
5 Correct 27 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1108 KB Output is correct
2 Correct 12 ms 1128 KB Output is correct
3 Correct 12 ms 1108 KB Output is correct
4 Correct 7 ms 1136 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 1140 KB Output is correct
7 Correct 13 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2148 KB Output is correct
2 Correct 22 ms 1960 KB Output is correct
3 Correct 43 ms 3740 KB Output is correct
4 Correct 27 ms 3580 KB Output is correct
5 Correct 13 ms 2008 KB Output is correct
6 Correct 23 ms 3464 KB Output is correct
7 Correct 30 ms 4104 KB Output is correct
8 Correct 18 ms 1964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 49 ms 3804 KB Output is correct
28 Correct 49 ms 3796 KB Output is correct
29 Correct 53 ms 3788 KB Output is correct
30 Correct 51 ms 3804 KB Output is correct
31 Correct 27 ms 3532 KB Output is correct
32 Correct 11 ms 1108 KB Output is correct
33 Correct 12 ms 1128 KB Output is correct
34 Correct 12 ms 1108 KB Output is correct
35 Correct 7 ms 1136 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 11 ms 1140 KB Output is correct
38 Correct 13 ms 1108 KB Output is correct
39 Correct 24 ms 2148 KB Output is correct
40 Correct 22 ms 1960 KB Output is correct
41 Correct 43 ms 3740 KB Output is correct
42 Correct 27 ms 3580 KB Output is correct
43 Correct 13 ms 2008 KB Output is correct
44 Correct 23 ms 3464 KB Output is correct
45 Correct 30 ms 4104 KB Output is correct
46 Correct 18 ms 1964 KB Output is correct
47 Correct 29 ms 1996 KB Output is correct
48 Correct 25 ms 2024 KB Output is correct
49 Correct 52 ms 3800 KB Output is correct
50 Correct 27 ms 3524 KB Output is correct
51 Correct 23 ms 2764 KB Output is correct
52 Correct 31 ms 3632 KB Output is correct
53 Correct 27 ms 3660 KB Output is correct
54 Correct 30 ms 4312 KB Output is correct
55 Correct 40 ms 3760 KB Output is correct