Submission #949978

# Submission time Handle Problem Language Result Execution time Memory
949978 2024-03-20T02:20:51 Z berr Global Warming (CEOI18_glo) C++17
100 / 100
546 ms 28352 KB
#include <bits/stdc++.h>
using namespace std;
 
int st[4*200000+37];
map<int, int> c, e;
 
void update(int v, int l, int r, int pos, int val){
    if (l==r){ st[v] = val; return;}
 
    int mid = (r+l) / 2;
 
    if (pos <= mid) update(v*2, l, mid, pos, val);
    else update(v*2+1, mid+1, r, pos, val);
 
    st[v] = max(st[v*2+1], st[v*2]);
}
 
int get(int v, int l, int r, int tl, int tr){
    if(r<l || tl > r || tr < l || tr<tl) return 0;
    if(l>=tl && r<= tr) return st[v];
    int mid = (r+l) / 2;
 
    return max(get(v*2, l, mid, tl, tr), get(v*2+1, mid+1, r, tl, tr));
}
 
 
int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
 
    int n, x; cin >> n >> x;
    
    vector<int> a(n);
    vector<int> b, d, rb, rd;
 
 
    for (auto &i: a) cin >> i;
 
    for (int i = 0; i < n; i++){
        b.push_back(a[i]); d.push_back(a[i]-x);
    }
 
    sort(b.begin(), b.end());
    sort(d.begin(), d.end());
    int cnt=0;
 
    for (int i = 0; i < b.size(); i++){
        if(c.count(b[i])==0) c[b[i]] = cnt, cnt++;
    }
 
    cnt=0;
 
    for(int i=0; i<n; i++){
        if(e.count(d[i])==0) e[d[i]] = cnt, cnt++;
    }
 
    vector<int> pr(n), sf(n);
    int ans=0;
 
    for(int i=n-1; i>=0; i--){
        sf[i] = max(0, get(1, 0, n+1, c[a[i]]+1, n+1)) +1;
        ans=max(ans, sf[i]);
        update(1, 0, n+1, c[a[i]], sf[i]);
    }
 
    memset(st, 0, sizeof(st)); 
 
    
    for(int i=0; i<n; i++){
    
        int s=-1;
        for(int l=20; l>=0; l--){
            int tmp=s+(1LL<<l);
            if(tmp<n &&d[tmp] < a[i]){
                s=tmp;
            }
        }
 
        if(s!=-1)
        ans=max(ans, max(0, get(1, 0, n+1, 0, e[d[s]]))+sf[i]);
        
        pr[i] = max(0, get(1, 0, n+1, 0, e[a[i]-x]-1)) +1;
 
        update(1, 0, n+1, e[a[i]-x], pr[i]);
    
    }
 
 
 
 
    cout<<ans;
}

Compilation message

glo.cpp: In function 'int32_t main()':
glo.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < b.size(); i++){
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3416 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3400 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3416 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3400 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
15 Correct 1 ms 3420 KB Output is correct
16 Correct 1 ms 3420 KB Output is correct
17 Correct 1 ms 3536 KB Output is correct
18 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3416 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3400 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
15 Correct 1 ms 3420 KB Output is correct
16 Correct 1 ms 3420 KB Output is correct
17 Correct 1 ms 3536 KB Output is correct
18 Correct 1 ms 3420 KB Output is correct
19 Correct 2 ms 3636 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3544 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 2 ms 3672 KB Output is correct
25 Correct 2 ms 3420 KB Output is correct
26 Correct 2 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 518 ms 28224 KB Output is correct
2 Correct 509 ms 28184 KB Output is correct
3 Correct 513 ms 28352 KB Output is correct
4 Correct 544 ms 28092 KB Output is correct
5 Correct 247 ms 17884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 9676 KB Output is correct
2 Correct 97 ms 9560 KB Output is correct
3 Correct 105 ms 9932 KB Output is correct
4 Correct 54 ms 7120 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 51 ms 6992 KB Output is correct
7 Correct 82 ms 9680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 15904 KB Output is correct
2 Correct 208 ms 15876 KB Output is correct
3 Correct 468 ms 28352 KB Output is correct
4 Correct 232 ms 18068 KB Output is correct
5 Correct 151 ms 15536 KB Output is correct
6 Correct 298 ms 26364 KB Output is correct
7 Correct 289 ms 26816 KB Output is correct
8 Correct 188 ms 16068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3416 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3400 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
15 Correct 1 ms 3420 KB Output is correct
16 Correct 1 ms 3420 KB Output is correct
17 Correct 1 ms 3536 KB Output is correct
18 Correct 1 ms 3420 KB Output is correct
19 Correct 2 ms 3636 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3544 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 2 ms 3672 KB Output is correct
25 Correct 2 ms 3420 KB Output is correct
26 Correct 2 ms 3676 KB Output is correct
27 Correct 518 ms 28224 KB Output is correct
28 Correct 509 ms 28184 KB Output is correct
29 Correct 513 ms 28352 KB Output is correct
30 Correct 544 ms 28092 KB Output is correct
31 Correct 247 ms 17884 KB Output is correct
32 Correct 99 ms 9676 KB Output is correct
33 Correct 97 ms 9560 KB Output is correct
34 Correct 105 ms 9932 KB Output is correct
35 Correct 54 ms 7120 KB Output is correct
36 Correct 1 ms 3420 KB Output is correct
37 Correct 51 ms 6992 KB Output is correct
38 Correct 82 ms 9680 KB Output is correct
39 Correct 213 ms 15904 KB Output is correct
40 Correct 208 ms 15876 KB Output is correct
41 Correct 468 ms 28352 KB Output is correct
42 Correct 232 ms 18068 KB Output is correct
43 Correct 151 ms 15536 KB Output is correct
44 Correct 298 ms 26364 KB Output is correct
45 Correct 289 ms 26816 KB Output is correct
46 Correct 188 ms 16068 KB Output is correct
47 Correct 222 ms 15892 KB Output is correct
48 Correct 221 ms 15700 KB Output is correct
49 Correct 546 ms 28172 KB Output is correct
50 Correct 227 ms 18068 KB Output is correct
51 Correct 220 ms 16604 KB Output is correct
52 Correct 336 ms 27524 KB Output is correct
53 Correct 311 ms 27568 KB Output is correct
54 Correct 314 ms 28092 KB Output is correct
55 Correct 432 ms 28252 KB Output is correct