Submission #1284772

#TimeUsernameProblemLanguageResultExecution timeMemory
1284772celesGlobal Warming (CEOI18_glo)C++20
10 / 100
63 ms3636 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 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 b[N];
int a[2][N];
int f[2][N];
int res[2];

int Find(int t, int x) {
    int l = 1, r = res[t], j = 0;

    while (l <= r) {
        int m = (l + r) >> 1;
        if (x > f[t][m]) {
            j = m;
            l = m + 1;
        } else r = m - 1;
    }

    return j;
}

ll Solve() {
    f[0][1] = a[0][1]; res[0] = 1;
    f[1][1] = a[1][1]; res[1] = 1;

    for (int i = 2; i <= n; i++) {
        int j = Find(0, a[0][i]);
        int k = max(Find(0, a[1][i]),
                    Find(1, a[1][i]));

        if (j == res[0]) f[0][++res[0]] = a[0][i];
        else if (a[0][i] < f[0][j + 1])
                f[0][j + 1] = a[0][i];

        if (k == res[1]) f[1][++res[1]] = a[1][i];
        else if (a[1][i] < f[1][k + 1])
                f[1][k + 1] = a[1][i];
    }

    return max(res[0], res[1]);
}

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>>b[i];

    for (int i = 1; i <= n; i++) {
        a[0][i] = b[i];
        a[1][i] = b[i] + x;
    }

    ll res1 = Solve();

    for (int i = 1; i <= n; i++) {
        a[0][i] = b[i] - x;
        a[1][i] = b[i];
    }

    ll res2 = Solve();

    cout<<min(res1, res2);

    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:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         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...