Submission #933727

#TimeUsernameProblemLanguageResultExecution timeMemory
933727a_l_i_r_e_z_aGlobal Warming (CEOI18_glo)C++17
100 / 100
45 ms5292 KiB
// In the name of God
// Hope is last to die

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

const int maxn = 2e5 + 5;
const int inf = 1e9 + 7;
int n, d, a[maxn], dpl[maxn], dpr[maxn];
vector<int> vec;

int32_t 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];
        int it = lower_bound(all(vec), a[i]) - vec.begin();
        if(it == vec.size()) vec.pb(a[i]);
        else vec[it] = a[i];
        dpl[i] = it + 1;
        a[i] *= -1;
    }
    vec.clear();
    reverse(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++){
        int it = lower_bound(all(vec), a[i] + d) - vec.begin();
        dpr[n - i + 1] = it + 1;
        it = lower_bound(all(vec), a[i]) - vec.begin();
        if(it == vec.size()) vec.pb(a[i]);
        else vec[it] = a[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) smax(ans, dpl[i] + dpr[i] - 1);
    cout << ans << '\n';

    return 0;
}

Compilation message (stderr)

glo.cpp: In function 'int32_t main()':
glo.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if(it == vec.size()) vec.pb(a[i]);
      |            ~~~^~~~~~~~~~~~~
glo.cpp:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(it == vec.size()) vec.pb(a[i]);
      |            ~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...