Submission #836005

# Submission time Handle Problem Language Result Execution time Memory
836005 2023-08-24T04:44:07 Z enerelt14 Global Warming (CEOI18_glo) C++14
100 / 100
53 ms 4304 KB
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

#define pb push_back

const int MX = 2e5 + 5;

int n, x, t[MX], num[MX];
vector<int> lis;

int find(int l, int r, int val) {
	if(l == r) {
		if(lis[l] < val) return l;
		else return l - 1;
	}
	int mid = (l + r) / 2;
	if(lis[mid] < val) return find(mid + 1, r, val);
	else return find(l, mid, val);
}

int rfind(int l, int r, int val) {
	if(l == r) {
		if(lis[l] > val) return l;
		else return l - 1;
	}
	int mid = (l + r) / 2;
	if(lis[mid] > val) return rfind(mid + 1, r, val);
	else return rfind(l, mid, val);
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> t[i];
	num[1] = 1;
	lis.pb(t[1]);
	for(int i = 2; i <= n; i++) {
		num[i] = find(0, (int)lis.size() - 1, t[i]) + 2;
		if(num[i] == (int)lis.size() + 1) lis.pb(t[i]);
		else lis[num[i] - 1] = t[i];
	}
	int ans = num[n];
	lis.clear();
	lis.pb(t[n] + x);
	for(int i = n - 1; i > 0; i--) {
		int k = rfind(0, (int)lis.size() - 1, t[i]) + 1;
		ans = max(ans, k + num[i]);
		k = rfind(0, (int)lis.size() - 1, t[i] + x) + 1;
		if(k == (int)lis.size()) lis.pb(t[i] + x);
		else lis[k] = t[i] + x;
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 0 ms 212 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 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 53 ms 1840 KB Output is correct
2 Correct 49 ms 3804 KB Output is correct
3 Correct 50 ms 3788 KB Output is correct
4 Correct 48 ms 3792 KB Output is correct
5 Correct 26 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 724 KB Output is correct
2 Correct 12 ms 1108 KB Output is correct
3 Correct 12 ms 1208 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1140 KB Output is correct
7 Correct 9 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1108 KB Output is correct
2 Correct 24 ms 2004 KB Output is correct
3 Correct 40 ms 3704 KB Output is correct
4 Correct 27 ms 3468 KB Output is correct
5 Correct 13 ms 2008 KB Output is correct
6 Correct 22 ms 3412 KB Output is correct
7 Correct 26 ms 4184 KB Output is correct
8 Correct 17 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 0 ms 212 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 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 53 ms 1840 KB Output is correct
28 Correct 49 ms 3804 KB Output is correct
29 Correct 50 ms 3788 KB Output is correct
30 Correct 48 ms 3792 KB Output is correct
31 Correct 26 ms 3540 KB Output is correct
32 Correct 11 ms 724 KB Output is correct
33 Correct 12 ms 1108 KB Output is correct
34 Correct 12 ms 1208 KB Output is correct
35 Correct 6 ms 1236 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 6 ms 1140 KB Output is correct
38 Correct 9 ms 1108 KB Output is correct
39 Correct 20 ms 1108 KB Output is correct
40 Correct 24 ms 2004 KB Output is correct
41 Correct 40 ms 3704 KB Output is correct
42 Correct 27 ms 3468 KB Output is correct
43 Correct 13 ms 2008 KB Output is correct
44 Correct 22 ms 3412 KB Output is correct
45 Correct 26 ms 4184 KB Output is correct
46 Correct 17 ms 2056 KB Output is correct
47 Correct 25 ms 2000 KB Output is correct
48 Correct 25 ms 2124 KB Output is correct
49 Correct 48 ms 3800 KB Output is correct
50 Correct 26 ms 3532 KB Output is correct
51 Correct 23 ms 2776 KB Output is correct
52 Correct 27 ms 3668 KB Output is correct
53 Correct 26 ms 3704 KB Output is correct
54 Correct 26 ms 4304 KB Output is correct
55 Correct 38 ms 3832 KB Output is correct