제출 #849202

#제출 시각아이디문제언어결과실행 시간메모리
849202quanlt206Global Warming (CEOI18_glo)C++14
100 / 100
51 ms7088 KiB
#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;

template<class A, class B>
    bool maximize(A& x, B y) {
        if (x < y) return x = y, true; else return false;
    }
template<class A, class B>
    bool minimize(A& x, B y) {
        if (x > y) return x = y, true; else return false;
    }
/* END OF TEMPLATE */

const int N = 2e5 + 7;

int n, d, a[N], b[N], f[N], f2[N], g[N], m, ed[N];

int chat(int x, int a[]) {
    int d = 1, c = m, res, g;
    while (d <= c) {
        g = (d + c) >> 1;
        if (a[ed[g]] < x) res = ed[g], d = g + 1; else c = g - 1;
    }
    return res;
}

void buildLISarray(int a[], int f[], int f2[], bool changeF2) {
    m = 1;
    ed[1] = 0;
    f[0] = 1;
    a[0] = -2e9;
    FOR(i, 1, n) {
        int j = chat(a[i], a), k = f[j] + 1;
        if (changeF2) f2[i] = f[chat(a[i] + d, a)] + 1;
        if (m < k) {
            m = k;
            ed[m] = i;
        }
        else
        if (a[ed[k]] > a[i]) ed[k] = i;
        f[i] = k;
    }
    FOR(i, 1, n) f[i]--;
    if (changeF2) {
        FOR(i, 1, n) f2[i]--;
    }
}

int chat2(int x, int a[]) {
    int d = 1, c = m, res, g;
    while (d <= c) {
        g = (d + c) >> 1;
        if (a[ed[g]] > x) res = ed[g], d = g + 1; else c = g - 1;
    }
    return res;
}

void buildLISarray2(int a[], int f[]) {
    m = 1;
    ed[1] = n + 1;
    f[n + 1] = 1;
    a[n + 1] = 2e9 + 7;
    FORD(i, n, 1) {
        int j = chat2(a[i], a), k = f[j] + 1;
        if (m < k) {
            m = k;
            ed[m] = i;
        }
        else
        if (a[ed[k]] < a[i]) ed[k] = i;
        f[i] = k;
    }
    FOR(i, 1, n) f[i]--;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>d;
    FOR(i, 1, n) cin>>a[i];
    buildLISarray(a, f, f2, true);
    FOR(i, 1, n) b[i] = a[i] + d;
    buildLISarray2(b, g);
    int res = 1;
    FOR(i, 1, n) maximize(res, f2[i] + g[i] - 1);
    cout<<res;
    return 0;

}

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int chat(int, int*)':
glo.cpp:52:12: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |     return res;
      |            ^~~
glo.cpp: In function 'void buildLISarray(int*, int*, int*, bool)':
glo.cpp:61:38: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |         int j = chat(a[i], a), k = f[j] + 1;
      |                                      ^
glo.cpp:62:37: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |         if (changeF2) f2[i] = f[chat(a[i] + d, a)] + 1;
      |                                 ~~~~^~~~~~~~~~~~~
glo.cpp: In function 'int chat2(int, int*)':
glo.cpp:83:12: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   83 |     return res;
      |            ^~~
glo.cpp: In function 'void buildLISarray2(int*, int*)':
glo.cpp:92:39: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   92 |         int j = chat2(a[i], a), k = f[j] + 1;
      |                                       ^
#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...