Submission #792935

# Submission time Handle Problem Language Result Execution time Memory
792935 2023-07-25T11:16:31 Z PoonYaPat Global Warming (CEOI18_glo) C++14
100 / 100
129 ms 139872 KB
#include <bits/stdc++.h>
using namespace std;

int n,d,a[200005],change[200005];
stack<int> st[200005];

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

    vector<int> v1,v2;
    for (int i=n; i>=1; --i) {
        auto it=lower_bound(v1.begin(),v1.end(),-a[i]-d);
        if (it==v1.end()) v1.push_back(-a[i]-d), st[v1.size()].push(a[i]+d), change[i]=v1.size();
        else if (*it==-a[i]-d) change[i]=-1;
        else {
            *it=-a[i]-d;
            change[i]=it-v1.begin()+1;
            st[it-v1.begin()+1].push(a[i]+d);
        }
    }
    for (int i=0; i<v1.size(); ++i) v1[i]=-v1[i];
    reverse(v1.begin(),v1.end());

    int ans=0;
    for (int i=1; i<=n; ++i) {
        if (change[i]!=-1) {
            st[change[i]].pop();
            if (st[change[i]].size()) v1[v1.size()-change[i]]=st[change[i]].top();
            else v1[v1.size()-change[i]]=0;
        }

        auto it=lower_bound(v2.begin(),v2.end(),a[i]);
        if (it==v2.end()) {
            v2.push_back(a[i]);
            ans=max(ans,(int)(v2.size())+(int)(v1.end()-upper_bound(v1.begin(),v1.end(),a[i])));
        } else if (*it!=a[i]) {
            *it=a[i];
            ans=max(ans,(int)(it-v2.begin()+1)+(int)(v1.end()-upper_bound(v1.begin(),v1.end(),a[i])));
        }
    }
    cout<<ans;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i=0; i<v1.size(); ++i) v1[i]=-v1[i];
      |                   ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 134952 KB Output is correct
2 Correct 62 ms 134888 KB Output is correct
3 Correct 80 ms 134872 KB Output is correct
4 Correct 64 ms 134852 KB Output is correct
5 Correct 70 ms 134988 KB Output is correct
6 Correct 63 ms 134864 KB Output is correct
7 Correct 64 ms 134936 KB Output is correct
8 Correct 78 ms 134952 KB Output is correct
9 Correct 63 ms 134888 KB Output is correct
10 Correct 63 ms 134924 KB Output is correct
11 Correct 62 ms 134864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 134952 KB Output is correct
2 Correct 62 ms 134888 KB Output is correct
3 Correct 80 ms 134872 KB Output is correct
4 Correct 64 ms 134852 KB Output is correct
5 Correct 70 ms 134988 KB Output is correct
6 Correct 63 ms 134864 KB Output is correct
7 Correct 64 ms 134936 KB Output is correct
8 Correct 78 ms 134952 KB Output is correct
9 Correct 63 ms 134888 KB Output is correct
10 Correct 63 ms 134924 KB Output is correct
11 Correct 62 ms 134864 KB Output is correct
12 Correct 68 ms 134852 KB Output is correct
13 Correct 76 ms 134856 KB Output is correct
14 Correct 66 ms 134844 KB Output is correct
15 Correct 64 ms 134860 KB Output is correct
16 Correct 64 ms 134860 KB Output is correct
17 Correct 66 ms 134828 KB Output is correct
18 Correct 63 ms 134852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 134952 KB Output is correct
2 Correct 62 ms 134888 KB Output is correct
3 Correct 80 ms 134872 KB Output is correct
4 Correct 64 ms 134852 KB Output is correct
5 Correct 70 ms 134988 KB Output is correct
6 Correct 63 ms 134864 KB Output is correct
7 Correct 64 ms 134936 KB Output is correct
8 Correct 78 ms 134952 KB Output is correct
9 Correct 63 ms 134888 KB Output is correct
10 Correct 63 ms 134924 KB Output is correct
11 Correct 62 ms 134864 KB Output is correct
12 Correct 68 ms 134852 KB Output is correct
13 Correct 76 ms 134856 KB Output is correct
14 Correct 66 ms 134844 KB Output is correct
15 Correct 64 ms 134860 KB Output is correct
16 Correct 64 ms 134860 KB Output is correct
17 Correct 66 ms 134828 KB Output is correct
18 Correct 63 ms 134852 KB Output is correct
19 Correct 65 ms 134852 KB Output is correct
20 Correct 65 ms 134948 KB Output is correct
21 Correct 64 ms 134968 KB Output is correct
22 Correct 65 ms 134956 KB Output is correct
23 Correct 67 ms 134912 KB Output is correct
24 Correct 63 ms 134976 KB Output is correct
25 Correct 67 ms 134968 KB Output is correct
26 Correct 64 ms 134976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 138924 KB Output is correct
2 Correct 118 ms 139028 KB Output is correct
3 Correct 129 ms 138956 KB Output is correct
4 Correct 111 ms 139000 KB Output is correct
5 Correct 95 ms 138772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 135836 KB Output is correct
2 Correct 73 ms 135940 KB Output is correct
3 Correct 76 ms 135940 KB Output is correct
4 Correct 72 ms 135948 KB Output is correct
5 Correct 65 ms 134936 KB Output is correct
6 Correct 72 ms 135880 KB Output is correct
7 Correct 71 ms 135908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 136808 KB Output is correct
2 Correct 83 ms 136812 KB Output is correct
3 Correct 103 ms 139040 KB Output is correct
4 Correct 93 ms 138768 KB Output is correct
5 Correct 85 ms 136844 KB Output is correct
6 Correct 96 ms 139160 KB Output is correct
7 Correct 99 ms 139696 KB Output is correct
8 Correct 91 ms 136908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 134952 KB Output is correct
2 Correct 62 ms 134888 KB Output is correct
3 Correct 80 ms 134872 KB Output is correct
4 Correct 64 ms 134852 KB Output is correct
5 Correct 70 ms 134988 KB Output is correct
6 Correct 63 ms 134864 KB Output is correct
7 Correct 64 ms 134936 KB Output is correct
8 Correct 78 ms 134952 KB Output is correct
9 Correct 63 ms 134888 KB Output is correct
10 Correct 63 ms 134924 KB Output is correct
11 Correct 62 ms 134864 KB Output is correct
12 Correct 68 ms 134852 KB Output is correct
13 Correct 76 ms 134856 KB Output is correct
14 Correct 66 ms 134844 KB Output is correct
15 Correct 64 ms 134860 KB Output is correct
16 Correct 64 ms 134860 KB Output is correct
17 Correct 66 ms 134828 KB Output is correct
18 Correct 63 ms 134852 KB Output is correct
19 Correct 65 ms 134852 KB Output is correct
20 Correct 65 ms 134948 KB Output is correct
21 Correct 64 ms 134968 KB Output is correct
22 Correct 65 ms 134956 KB Output is correct
23 Correct 67 ms 134912 KB Output is correct
24 Correct 63 ms 134976 KB Output is correct
25 Correct 67 ms 134968 KB Output is correct
26 Correct 64 ms 134976 KB Output is correct
27 Correct 109 ms 138924 KB Output is correct
28 Correct 118 ms 139028 KB Output is correct
29 Correct 129 ms 138956 KB Output is correct
30 Correct 111 ms 139000 KB Output is correct
31 Correct 95 ms 138772 KB Output is correct
32 Correct 74 ms 135836 KB Output is correct
33 Correct 73 ms 135940 KB Output is correct
34 Correct 76 ms 135940 KB Output is correct
35 Correct 72 ms 135948 KB Output is correct
36 Correct 65 ms 134936 KB Output is correct
37 Correct 72 ms 135880 KB Output is correct
38 Correct 71 ms 135908 KB Output is correct
39 Correct 83 ms 136808 KB Output is correct
40 Correct 83 ms 136812 KB Output is correct
41 Correct 103 ms 139040 KB Output is correct
42 Correct 93 ms 138768 KB Output is correct
43 Correct 85 ms 136844 KB Output is correct
44 Correct 96 ms 139160 KB Output is correct
45 Correct 99 ms 139696 KB Output is correct
46 Correct 91 ms 136908 KB Output is correct
47 Correct 88 ms 136880 KB Output is correct
48 Correct 86 ms 136860 KB Output is correct
49 Correct 111 ms 139008 KB Output is correct
50 Correct 93 ms 138820 KB Output is correct
51 Correct 87 ms 138120 KB Output is correct
52 Correct 98 ms 138932 KB Output is correct
53 Correct 103 ms 139320 KB Output is correct
54 Correct 101 ms 139872 KB Output is correct
55 Correct 107 ms 138956 KB Output is correct