Submission #895268

# Submission time Handle Problem Language Result Execution time Memory
895268 2023-12-29T17:19:27 Z TahirAliyev Global Warming (CEOI18_glo) C++17
100 / 100
281 ms 33484 KB
#include <bits/stdc++.h>

#define ll long long
#define oo 1e9
#define pii pair<int, int>

using namespace std;

const int MAX = 2e5 + 5, treesize = MAX * 21, CAP = 1e9 + 9;

int n, x;
int arr[MAX];
int tree[treesize], L[treesize], R[treesize];
int LIS[MAX];

int nxt = 2;

void update(int node, int l, int r, int pos, int val){
    if(l == r){
        tree[node] = max(val, tree[node]);
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid){
        if(!L[node]) L[node] = nxt++;
        update(L[node], l, mid, pos, val);
    }
    else{
        if(!R[node]) R[node] = nxt++;
        update(R[node], mid + 1, r, pos, val);
    }
    tree[node] = max(tree[L[node]], tree[R[node]]);
}

int ask(int node, int l, int r, int ql, int qr){
    if(!node) return 0;
    if(qr < l || r < ql) return 0;
    if(ql <= l && r <= qr) return tree[node];
    int mid = (l + r) / 2;
    return max(ask(L[node], l, mid, ql, qr), ask(R[node], mid + 1, r, ql, qr));
}

void solve(){
    cin >> n >> x;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }
    vector<int> v;
    for(int i = 1; i <= n; i++){
        int pos = lower_bound(v.begin(), v.end(), arr[i]) - v.begin();
        LIS[i] = pos + 1;
        if(pos == v.size()){
            v.push_back(arr[i]);
        }
        else{
            v[pos] = arr[i];
        }
    }
    int ans = 0;
    for(int i = n; i >= 1; i--){
        ans = max(ans, LIS[i] + ask(1, 1, CAP, max(arr[i] - x + 1, 1), arr[i] + x - 1));
        update(1, 1, CAP, arr[i], ask(1, 1, CAP, arr[i] + 1, CAP) + 1);
    }
    cout << ans << '\n';
}

int main()
{
    int t = 1;
    while(t){
        t--;
        solve();
    }
}

Compilation message

glo.cpp: In function 'void solve()':
glo.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if(pos == v.size()){
      |            ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 428 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 428 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 33336 KB Output is correct
2 Correct 261 ms 33364 KB Output is correct
3 Correct 249 ms 33484 KB Output is correct
4 Correct 242 ms 33364 KB Output is correct
5 Correct 143 ms 19656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 10324 KB Output is correct
2 Correct 50 ms 10324 KB Output is correct
3 Correct 63 ms 10320 KB Output is correct
4 Correct 36 ms 6392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 49 ms 3652 KB Output is correct
7 Correct 47 ms 7792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 18416 KB Output is correct
2 Correct 102 ms 18428 KB Output is correct
3 Correct 201 ms 33280 KB Output is correct
4 Correct 121 ms 19236 KB Output is correct
5 Correct 57 ms 4944 KB Output is correct
6 Correct 106 ms 6740 KB Output is correct
7 Correct 119 ms 6836 KB Output is correct
8 Correct 85 ms 13652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 428 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 242 ms 33336 KB Output is correct
28 Correct 261 ms 33364 KB Output is correct
29 Correct 249 ms 33484 KB Output is correct
30 Correct 242 ms 33364 KB Output is correct
31 Correct 143 ms 19656 KB Output is correct
32 Correct 53 ms 10324 KB Output is correct
33 Correct 50 ms 10324 KB Output is correct
34 Correct 63 ms 10320 KB Output is correct
35 Correct 36 ms 6392 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 49 ms 3652 KB Output is correct
38 Correct 47 ms 7792 KB Output is correct
39 Correct 93 ms 18416 KB Output is correct
40 Correct 102 ms 18428 KB Output is correct
41 Correct 201 ms 33280 KB Output is correct
42 Correct 121 ms 19236 KB Output is correct
43 Correct 57 ms 4944 KB Output is correct
44 Correct 106 ms 6740 KB Output is correct
45 Correct 119 ms 6836 KB Output is correct
46 Correct 85 ms 13652 KB Output is correct
47 Correct 111 ms 18512 KB Output is correct
48 Correct 115 ms 18512 KB Output is correct
49 Correct 281 ms 33472 KB Output is correct
50 Correct 139 ms 19400 KB Output is correct
51 Correct 113 ms 5288 KB Output is correct
52 Correct 192 ms 7068 KB Output is correct
53 Correct 121 ms 7368 KB Output is correct
54 Correct 157 ms 7112 KB Output is correct
55 Correct 193 ms 24440 KB Output is correct