Submission #481754

# Submission time Handle Problem Language Result Execution time Memory
481754 2021-10-21T15:46:38 Z BackNoob Global Warming (CEOI18_glo) C++14
100 / 100
57 ms 5332 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define mask(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
using namespace std;
const int mxN = 3e5 + 227;
const ll inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

int n , x; 
int a[mxN];
int l[mxN];
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("task.inp" , "r" , stdin);
    //freopen("task.out" , "w" , stdout);
    
    cin >> n >> x;
    for(int i = 1 ; i <= n ; i++) cin >> a[i];

    int res = 0;
    vector<ll> lis(n , infll);
	for(int i = 1 ; i <= n ; i++) {
		int pos = lower_bound(lis.begin() , lis.end() , a[i]) - lis.begin();
		l[i] = pos + 1;
		maximize(res , l[i]);
		lis[pos] = a[i];
	}
 	
	lis.assign(n , infll);

	for(int i = n ; i >= 1 ; i--) {
		int pos = lower_bound(lis.begin() , lis.end() , -(a[i] - x)) - lis.begin();
		maximize(res , l[i] + pos);

		pos = lower_bound(lis.begin() , lis.end() , -a[i]) - lis.begin();
		lis[pos] = -a[i];
	}


	cout << res;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3380 KB Output is correct
2 Correct 48 ms 3396 KB Output is correct
3 Correct 57 ms 3460 KB Output is correct
4 Correct 50 ms 3324 KB Output is correct
5 Correct 34 ms 3352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1100 KB Output is correct
2 Correct 12 ms 1100 KB Output is correct
3 Correct 12 ms 1100 KB Output is correct
4 Correct 9 ms 1100 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 9 ms 1356 KB Output is correct
7 Correct 12 ms 1608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1836 KB Output is correct
2 Correct 23 ms 2764 KB Output is correct
3 Correct 47 ms 5304 KB Output is correct
4 Correct 38 ms 4540 KB Output is correct
5 Correct 18 ms 2380 KB Output is correct
6 Correct 29 ms 4420 KB Output is correct
7 Correct 34 ms 5068 KB Output is correct
8 Correct 19 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 49 ms 3380 KB Output is correct
28 Correct 48 ms 3396 KB Output is correct
29 Correct 57 ms 3460 KB Output is correct
30 Correct 50 ms 3324 KB Output is correct
31 Correct 34 ms 3352 KB Output is correct
32 Correct 12 ms 1100 KB Output is correct
33 Correct 12 ms 1100 KB Output is correct
34 Correct 12 ms 1100 KB Output is correct
35 Correct 9 ms 1100 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 9 ms 1356 KB Output is correct
38 Correct 12 ms 1608 KB Output is correct
39 Correct 22 ms 1836 KB Output is correct
40 Correct 23 ms 2764 KB Output is correct
41 Correct 47 ms 5304 KB Output is correct
42 Correct 38 ms 4540 KB Output is correct
43 Correct 18 ms 2380 KB Output is correct
44 Correct 29 ms 4420 KB Output is correct
45 Correct 34 ms 5068 KB Output is correct
46 Correct 19 ms 2892 KB Output is correct
47 Correct 24 ms 2788 KB Output is correct
48 Correct 26 ms 2780 KB Output is correct
49 Correct 55 ms 5304 KB Output is correct
50 Correct 36 ms 4528 KB Output is correct
51 Correct 31 ms 3512 KB Output is correct
52 Correct 38 ms 4656 KB Output is correct
53 Correct 31 ms 4676 KB Output is correct
54 Correct 35 ms 5328 KB Output is correct
55 Correct 41 ms 5332 KB Output is correct