제출 #1284801

#제출 시각아이디문제언어결과실행 시간메모리
1284801celesGlobal Warming (CEOI18_glo)C++20
10 / 100
83 ms5228 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 - 1));

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

    cout<<ans;

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

컴파일 시 표준 에러 (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...