Submission #1284803

#TimeUsernameProblemLanguageResultExecution timeMemory
1284803celesGlobal Warming (CEOI18_glo)C++20
100 / 100
86 ms5224 KiB
#include <bits/stdc++.h>
using namespace std;
#define     ll long long
#define    pll pair<ll, ll>
#define    pii pair<int, int>
#define     fi first
#define     se second
#define     pb push_back
#define     all(v) (v).begin(), (v).end()
#define     Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end())
const int N = 2e5 + 5;

int n, x;
int a[N], f[N], dp[N];
int ans;

vector<int> pos;

int pre[N], suf[N];

void update(int bit[], int u, int val) {
    while (u < N) {
        bit[u] = max(bit[u], val);
        u += u & -u;
    }
}

int get(int bit[], int u) {
    int res = 0;
    while (u) {
        res = max(res, bit[u]);
        u -= u & -u;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "bseq"
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    if (fopen("task.inp", "r")) {
        freopen("task.inp", "r", stdin);
        freopen("task.out", "w", stdout);
    }
    cin>>n>>x;
    for (int i = 1; i <= n; i++) {
        cin>>a[i];
        f[i] = a[i];
        pos.push_back(a[i]);
    }

    pos.push_back(INT_MIN); Unique(pos);

    for (int i = 1; i <= n; i++) {
        a[i] = lower_bound(all(pos), a[i]) - pos.begin();

        dp[i] = get(pre, a[i] - 1) + 1;
        update(pre, a[i], dp[i]);
    }

    for (int i = n; i >= 1; i--) {
        int j = upper_bound(all(pos), f[i] - x) - pos.begin() - 1;
        ans = max(ans, dp[i] + get(suf, n - j + 2));

        update(suf, n - a[i] + 3, get(suf, n - a[i] + 2) + 1);
    }

    cout<<ans;

    cerr<<setprecision(3)<<fixed<<"Time elapsed: "<< 1.0 * clock() / CLOCKS_PER_SEC <<"s\n";
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen("task.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...