Submission #422577

# Submission time Handle Problem Language Result Execution time Memory
422577 2021-06-10T08:48:47 Z snasibov05 Global Warming (CEOI18_glo) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>

using namespace std;

#define oo 1000000000

int main() {
    int n, x; cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    int sz = 1;
    vector<int> dp(n);
    vector<int> c(n+1, oo);
    c[0] = 0;
    c[1] = v[0];
    dp[0] = 1;

    for (int i = 1; i < n; ++i) {
        if (v[i] < c[1]) c[1] = v[i], dp[i] = 1;
        else if (v[i] > c[sz]) c[sz+1] = v[i], dp[i] = ++sz;
        else {
            int k = lower_bound(c.begin(), c.end(), v[i]) - c.begin();
            c[k] = v[i];
            dp[i] = k;
        }
    }

    vector<int> sufdp(n);
    c.assign(0, n+1);
    c[0] = oo;
    c[1] = v[n-1] + x;
    dp[n-1] = 1;
    sz = 1;

    int ans = dp[n-1];

    for (int i = n-2; i >= 0; --i){
        if (v[i] > c[1]) ans = max(ans, dp[i]);
        else if (v[i] < c[sz]) ans = max(ans, dp[i] + sz);
        else{
            int k = upper_bound(c.begin(), c.end(), v[i]) - c.begin() - 1;
            ans = max(ans, dp[i] + k - 1);
        }

        if (v[i] + x > c[1]) c[1] = v[i] + x, dp[i] = 1;
        else if (v[i] + x < c[sz]) c[sz+1] = v[i] + x, dp[i] = ++sz;
        else{
            int k = upper_bound(c.begin(), c.end(), v[i] + x) - c.begin() - 1;
            c[k] = v[i] + x;
            dp[i] = k;
        }
    }

    cout << ans << "\n";

    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:45:21: error: 'upper_bound' was not declared in this scope
   45 |             int k = upper_bound(c.begin(), c.end(), v[i]) - c.begin() - 1;
      |                     ^~~~~~~~~~~
glo.cpp:52:21: error: 'upper_bound' was not declared in this scope
   52 |             int k = upper_bound(c.begin(), c.end(), v[i] + x) - c.begin() - 1;
      |                     ^~~~~~~~~~~