Submission #961072

# Submission time Handle Problem Language Result Execution time Memory
961072 2024-04-11T13:27:33 Z BF001 Global Warming (CEOI18_glo) C++17
100 / 100
53 ms 4700 KB
#include <bits/stdc++.h>
using namespace std;

#define N 200005

int n, a[N], cnt, lf[N], val[N], x;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
        
   	cin >> n >> x;
   	for (int i = 1; i <= n; i++) cin >> a[i];

   	for (int i = 1; i <= n; i++){
   		int l = 1, r = cnt, rt = 0;
   		while (l <= r){
   			int mid = (l + r) >> 1;
   			if (val[mid] < a[i]){
   				rt = mid;
   				l = mid + 1;
   			}
   			else r = mid - 1;
   		}
   		if (rt == cnt) cnt++;
   		val[rt + 1] = a[i];
   		lf[i] = rt + 1;
   	}

   	cnt = 0;
   	int res = 0;
   	for (int i = n; i >= 1; i--){
   		int l = 1, r = cnt, rt = 0;
   		while (l <= r){
   			int mid = (l + r) >> 1;
   			if (a[i] - x < val[mid]){
   				rt = mid;
   				l = mid + 1;
   			}
   			else r = mid - 1;
   		}
   		res = max(res, lf[i] + rt);
   		l = 1, r = cnt, rt = 0;
   		while (l <= r){
   			int mid = (l + r) >> 1;
   			if (a[i] < val[mid]){
   				l = mid + 1;
   				rt = mid;
   			}
   			else r = mid - 1;
   		}
   		if (rt == cnt) cnt++;
   		val[rt + 1] = a[i];
   	}

   	cout << res;

    return 0;
}     
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2656 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 4 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2544 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2656 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 4 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2544 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2656 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 4 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2544 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2520 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2516 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 4396 KB Output is correct
2 Correct 45 ms 4528 KB Output is correct
3 Correct 50 ms 4540 KB Output is correct
4 Correct 53 ms 4536 KB Output is correct
5 Correct 24 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2908 KB Output is correct
2 Correct 13 ms 3160 KB Output is correct
3 Correct 10 ms 2996 KB Output is correct
4 Correct 7 ms 2908 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 5 ms 3160 KB Output is correct
7 Correct 8 ms 3132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3416 KB Output is correct
2 Correct 21 ms 3468 KB Output is correct
3 Correct 40 ms 4420 KB Output is correct
4 Correct 28 ms 3912 KB Output is correct
5 Correct 12 ms 3036 KB Output is correct
6 Correct 24 ms 3932 KB Output is correct
7 Correct 26 ms 4668 KB Output is correct
8 Correct 16 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2656 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 4 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2544 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2520 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2516 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 49 ms 4396 KB Output is correct
28 Correct 45 ms 4528 KB Output is correct
29 Correct 50 ms 4540 KB Output is correct
30 Correct 53 ms 4536 KB Output is correct
31 Correct 24 ms 3920 KB Output is correct
32 Correct 11 ms 2908 KB Output is correct
33 Correct 13 ms 3160 KB Output is correct
34 Correct 10 ms 2996 KB Output is correct
35 Correct 7 ms 2908 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 5 ms 3160 KB Output is correct
38 Correct 8 ms 3132 KB Output is correct
39 Correct 18 ms 3416 KB Output is correct
40 Correct 21 ms 3468 KB Output is correct
41 Correct 40 ms 4420 KB Output is correct
42 Correct 28 ms 3912 KB Output is correct
43 Correct 12 ms 3036 KB Output is correct
44 Correct 24 ms 3932 KB Output is correct
45 Correct 26 ms 4668 KB Output is correct
46 Correct 16 ms 3420 KB Output is correct
47 Correct 23 ms 3416 KB Output is correct
48 Correct 25 ms 3416 KB Output is correct
49 Correct 45 ms 4700 KB Output is correct
50 Correct 22 ms 3908 KB Output is correct
51 Correct 19 ms 3420 KB Output is correct
52 Correct 22 ms 4224 KB Output is correct
53 Correct 19 ms 3932 KB Output is correct
54 Correct 23 ms 4544 KB Output is correct
55 Correct 39 ms 4652 KB Output is correct