Submission #97272

# Submission time Handle Problem Language Result Execution time Memory
97272 2019-02-14T17:19:26 Z dalgerok Global Warming (CEOI18_glo) C++14
100 / 100
425 ms 12744 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 2e5 + 5;



int n, d, a[N], b[N], val[N];
int t[8 * N];
vector < int > e;

void update(int v, int l, int r, int pos, int x){
    if(l == r){
        t[v] = max(t[v], x);
        return;
    }
    int mid = (r + l) >> 1;
    if(pos <= mid){
        update(v + v, l, mid, pos, x);
    }
    else{
        update(v + v + 1, mid + 1, r, pos, x);
    }
    t[v] = max(t[v + v], t[v + v + 1]);
}
int get(int v, int l, int r, int tl, int tr){
    if(l > r || l > tr || tl > r || tl > tr){
        return 0;
    }
    if(tl <= l && r <= tr){
        return t[v];
    }
    int mid = (r + l) >> 1;
    return max(get(v + v, l, mid, tl, tr), get(v + v + 1, mid + 1, r, tl, tr));
}

int 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];
        e.push_back(a[i]);
        e.push_back(a[i] + d);
    }
    sort(e.begin(), e.end());
    e.resize(unique(e.begin(), e.end()) - e.begin());
    for(int i = 1; i <= n; i++){
        b[i] = lower_bound(e.begin(), e.end(), a[i] + d) - e.begin() + 1;
        a[i] = lower_bound(e.begin(), e.end(), a[i]) - e.begin() + 1;
    }
    int sz = (int)e.size();
    for(int i = n; i >= 1; i--){
        update(1, 1, sz, b[i], (val[i] = get(1, 1, sz, b[i] + 1, sz) + 1));
    }
    int ans = t[1];
    memset(t, 0, sizeof(t));
    for(int i = 1; i <= n; i++){
        ans = max(ans, get(1, 1, sz, 1, b[i] - 1) + val[i]);
        update(1, 1, sz, a[i], get(1, 1, sz, 1, a[i] - 1) + 1);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6656 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 8 ms 6656 KB Output is correct
7 Correct 9 ms 6656 KB Output is correct
8 Correct 8 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 9 ms 6656 KB Output is correct
11 Correct 7 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6656 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 8 ms 6656 KB Output is correct
7 Correct 9 ms 6656 KB Output is correct
8 Correct 8 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 9 ms 6656 KB Output is correct
11 Correct 7 ms 6656 KB Output is correct
12 Correct 7 ms 6560 KB Output is correct
13 Correct 8 ms 6660 KB Output is correct
14 Correct 8 ms 6656 KB Output is correct
15 Correct 8 ms 6656 KB Output is correct
16 Correct 7 ms 6656 KB Output is correct
17 Correct 9 ms 6656 KB Output is correct
18 Correct 8 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6656 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 8 ms 6656 KB Output is correct
7 Correct 9 ms 6656 KB Output is correct
8 Correct 8 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 9 ms 6656 KB Output is correct
11 Correct 7 ms 6656 KB Output is correct
12 Correct 7 ms 6560 KB Output is correct
13 Correct 8 ms 6660 KB Output is correct
14 Correct 8 ms 6656 KB Output is correct
15 Correct 8 ms 6656 KB Output is correct
16 Correct 7 ms 6656 KB Output is correct
17 Correct 9 ms 6656 KB Output is correct
18 Correct 8 ms 6656 KB Output is correct
19 Correct 7 ms 6656 KB Output is correct
20 Correct 10 ms 6656 KB Output is correct
21 Correct 7 ms 6656 KB Output is correct
22 Correct 9 ms 6656 KB Output is correct
23 Correct 9 ms 6656 KB Output is correct
24 Correct 9 ms 6656 KB Output is correct
25 Correct 9 ms 6656 KB Output is correct
26 Correct 9 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 12744 KB Output is correct
2 Correct 362 ms 12564 KB Output is correct
3 Correct 393 ms 12520 KB Output is correct
4 Correct 353 ms 12520 KB Output is correct
5 Correct 158 ms 11832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 8288 KB Output is correct
2 Correct 90 ms 8308 KB Output is correct
3 Correct 77 ms 8308 KB Output is correct
4 Correct 48 ms 8180 KB Output is correct
5 Correct 7 ms 6656 KB Output is correct
6 Correct 52 ms 8052 KB Output is correct
7 Correct 66 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 224 ms 9732 KB Output is correct
2 Correct 189 ms 9856 KB Output is correct
3 Correct 425 ms 12520 KB Output is correct
4 Correct 188 ms 11800 KB Output is correct
5 Correct 132 ms 9328 KB Output is correct
6 Correct 229 ms 11744 KB Output is correct
7 Correct 211 ms 12392 KB Output is correct
8 Correct 138 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6656 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 6 ms 6656 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 8 ms 6656 KB Output is correct
7 Correct 9 ms 6656 KB Output is correct
8 Correct 8 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 9 ms 6656 KB Output is correct
11 Correct 7 ms 6656 KB Output is correct
12 Correct 7 ms 6560 KB Output is correct
13 Correct 8 ms 6660 KB Output is correct
14 Correct 8 ms 6656 KB Output is correct
15 Correct 8 ms 6656 KB Output is correct
16 Correct 7 ms 6656 KB Output is correct
17 Correct 9 ms 6656 KB Output is correct
18 Correct 8 ms 6656 KB Output is correct
19 Correct 7 ms 6656 KB Output is correct
20 Correct 10 ms 6656 KB Output is correct
21 Correct 7 ms 6656 KB Output is correct
22 Correct 9 ms 6656 KB Output is correct
23 Correct 9 ms 6656 KB Output is correct
24 Correct 9 ms 6656 KB Output is correct
25 Correct 9 ms 6656 KB Output is correct
26 Correct 9 ms 6656 KB Output is correct
27 Correct 339 ms 12744 KB Output is correct
28 Correct 362 ms 12564 KB Output is correct
29 Correct 393 ms 12520 KB Output is correct
30 Correct 353 ms 12520 KB Output is correct
31 Correct 158 ms 11832 KB Output is correct
32 Correct 81 ms 8288 KB Output is correct
33 Correct 90 ms 8308 KB Output is correct
34 Correct 77 ms 8308 KB Output is correct
35 Correct 48 ms 8180 KB Output is correct
36 Correct 7 ms 6656 KB Output is correct
37 Correct 52 ms 8052 KB Output is correct
38 Correct 66 ms 8276 KB Output is correct
39 Correct 224 ms 9732 KB Output is correct
40 Correct 189 ms 9856 KB Output is correct
41 Correct 425 ms 12520 KB Output is correct
42 Correct 188 ms 11800 KB Output is correct
43 Correct 132 ms 9328 KB Output is correct
44 Correct 229 ms 11744 KB Output is correct
45 Correct 211 ms 12392 KB Output is correct
46 Correct 138 ms 9708 KB Output is correct
47 Correct 199 ms 9664 KB Output is correct
48 Correct 172 ms 9756 KB Output is correct
49 Correct 421 ms 12712 KB Output is correct
50 Correct 183 ms 11924 KB Output is correct
51 Correct 151 ms 10604 KB Output is correct
52 Correct 197 ms 11880 KB Output is correct
53 Correct 198 ms 12068 KB Output is correct
54 Correct 255 ms 12556 KB Output is correct
55 Correct 302 ms 12712 KB Output is correct