Submission #933727

# Submission time Handle Problem Language Result Execution time Memory
933727 2024-02-26T07:58:37 Z a_l_i_r_e_z_a Global Warming (CEOI18_glo) C++17
100 / 100
45 ms 5292 KB
// In the name of God
// Hope is last to die

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

const int maxn = 2e5 + 5;
const int inf = 1e9 + 7;
int n, d, a[maxn], dpl[maxn], dpr[maxn];
vector<int> vec;

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> d;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        int it = lower_bound(all(vec), a[i]) - vec.begin();
        if(it == vec.size()) vec.pb(a[i]);
        else vec[it] = a[i];
        dpl[i] = it + 1;
        a[i] *= -1;
    }
    vec.clear();
    reverse(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++){
        int it = lower_bound(all(vec), a[i] + d) - vec.begin();
        dpr[n - i + 1] = it + 1;
        it = lower_bound(all(vec), a[i]) - vec.begin();
        if(it == vec.size()) vec.pb(a[i]);
        else vec[it] = a[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) smax(ans, dpl[i] + dpr[i] - 1);
    cout << ans << '\n';

    return 0;
}

Compilation message

glo.cpp: In function 'int32_t main()':
glo.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if(it == vec.size()) vec.pb(a[i]);
      |            ~~~^~~~~~~~~~~~~
glo.cpp:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(it == vec.size()) vec.pb(a[i]);
      |            ~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2508 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2516 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2508 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2516 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2504 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 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2508 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2516 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2504 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 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 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 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 4824 KB Output is correct
2 Correct 44 ms 4560 KB Output is correct
3 Correct 45 ms 4692 KB Output is correct
4 Correct 44 ms 4532 KB Output is correct
5 Correct 26 ms 4316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3164 KB Output is correct
2 Correct 10 ms 3164 KB Output is correct
3 Correct 11 ms 3164 KB Output is correct
4 Correct 6 ms 3624 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 5 ms 3164 KB Output is correct
7 Correct 8 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3480 KB Output is correct
2 Correct 18 ms 3420 KB Output is correct
3 Correct 37 ms 4684 KB Output is correct
4 Correct 22 ms 4316 KB Output is correct
5 Correct 11 ms 3552 KB Output is correct
6 Correct 19 ms 4316 KB Output is correct
7 Correct 26 ms 5068 KB Output is correct
8 Correct 16 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2508 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2516 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2504 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 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 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 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 44 ms 4824 KB Output is correct
28 Correct 44 ms 4560 KB Output is correct
29 Correct 45 ms 4692 KB Output is correct
30 Correct 44 ms 4532 KB Output is correct
31 Correct 26 ms 4316 KB Output is correct
32 Correct 11 ms 3164 KB Output is correct
33 Correct 10 ms 3164 KB Output is correct
34 Correct 11 ms 3164 KB Output is correct
35 Correct 6 ms 3624 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 5 ms 3164 KB Output is correct
38 Correct 8 ms 3164 KB Output is correct
39 Correct 19 ms 3480 KB Output is correct
40 Correct 18 ms 3420 KB Output is correct
41 Correct 37 ms 4684 KB Output is correct
42 Correct 22 ms 4316 KB Output is correct
43 Correct 11 ms 3552 KB Output is correct
44 Correct 19 ms 4316 KB Output is correct
45 Correct 26 ms 5068 KB Output is correct
46 Correct 16 ms 3532 KB Output is correct
47 Correct 21 ms 3660 KB Output is correct
48 Correct 22 ms 3420 KB Output is correct
49 Correct 44 ms 4668 KB Output is correct
50 Correct 22 ms 4316 KB Output is correct
51 Correct 20 ms 4056 KB Output is correct
52 Correct 23 ms 4572 KB Output is correct
53 Correct 20 ms 4696 KB Output is correct
54 Correct 23 ms 5292 KB Output is correct
55 Correct 35 ms 4692 KB Output is correct