답안 #1101918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101918 2024-10-17T07:32:48 Z anhthi Global Warming (CEOI18_glo) C++14
100 / 100
216 ms 27316 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define heap priority_queue
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)

template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }

template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }

template <class X>
    inline void compress(X &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }

int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }

const ll oo = (ll) 1e17;
const int INF = (int) 1e9 + 7, MOD = (int) 1e9 + 7;

const int N = 2e5 + 15;

void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; }
void sub(int &x, int y) { x -= y; if (x < 0) x += MOD; }

int n;
ll x, a[N], ID[N][3];

struct Seg {
    int n;
    vector<ll> st;
    Seg(int n) : n(n) {
        st.resize(2 * n + 5);
    }
    void upd(int p, ll d) {
        p += n;
        maximize(st[p], d);
        while (p > 1) {
            p >>= 1;
            st[p] = max(st[2 * p], st[2 * p + 1]);
        }
    }
    ll query(int l, int r) {
        l += n;
        r += n + 1;
        ll ans = 0;
        for (; l < r; l >>= 1, r >>= 1) {
            if (l & 1) maximize(ans, st[l++]);
            if (r & 1) maximize(ans, st[--r]);
        }
        return ans;
    }
    void reset() { st.assign(2 * n + 5, 0); }
};

int main(void) {
    // think what before starting to code
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> x;
    forn(i, 1, n) cin >> a[i];

    vector<ll> cps;
    forn(i, 1, n) forn(j, -1, 1) {
        cps.pb(a[i] + j * x);
    }
    compress(cps);
    forn(i, 1, n) forn(j, 0, 2) {
        ID[i][j] = lower_bound(all(cps), a[i] + (j - 1) * x) - cps.begin() + 1;    
    }
    int m = sz(cps);
    
    Seg s(m);
    vector<ll> pf(n + 1, 0), sf(n + 1, 0);
    forn(i, 1, n) {
        pf[i] = s.query(1, ID[i][1] - 1) + 1;
        s.upd(ID[i][1], pf[i]);
    }
    s.reset();
    ford(i, n, 1) {
        sf[i] = s.query(ID[i][1] + 1, m) + 1;
        s.upd(ID[i][1], sf[i]);
    }
    s.reset();
    ll ans = 0;
    
    forn(i, 1, n) {
        maximize(ans, sf[i] + s.query(1, ID[i][2] - 1));
        s.upd(ID[i][1], pf[i]);
    }

    cout << ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 170 ms 20916 KB Output is correct
2 Correct 168 ms 21000 KB Output is correct
3 Correct 170 ms 20920 KB Output is correct
4 Correct 173 ms 20992 KB Output is correct
5 Correct 84 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8644 KB Output is correct
2 Correct 42 ms 8644 KB Output is correct
3 Correct 43 ms 8644 KB Output is correct
4 Correct 24 ms 7372 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 25 ms 6860 KB Output is correct
7 Correct 39 ms 8080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 16828 KB Output is correct
2 Correct 100 ms 16828 KB Output is correct
3 Correct 216 ms 27316 KB Output is correct
4 Correct 102 ms 21684 KB Output is correct
5 Correct 66 ms 16328 KB Output is correct
6 Correct 130 ms 25524 KB Output is correct
7 Correct 126 ms 26308 KB Output is correct
8 Correct 81 ms 16828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 170 ms 20916 KB Output is correct
28 Correct 168 ms 21000 KB Output is correct
29 Correct 170 ms 20920 KB Output is correct
30 Correct 173 ms 20992 KB Output is correct
31 Correct 84 ms 18620 KB Output is correct
32 Correct 42 ms 8644 KB Output is correct
33 Correct 42 ms 8644 KB Output is correct
34 Correct 43 ms 8644 KB Output is correct
35 Correct 24 ms 7372 KB Output is correct
36 Correct 1 ms 508 KB Output is correct
37 Correct 25 ms 6860 KB Output is correct
38 Correct 39 ms 8080 KB Output is correct
39 Correct 110 ms 16828 KB Output is correct
40 Correct 100 ms 16828 KB Output is correct
41 Correct 216 ms 27316 KB Output is correct
42 Correct 102 ms 21684 KB Output is correct
43 Correct 66 ms 16328 KB Output is correct
44 Correct 130 ms 25524 KB Output is correct
45 Correct 126 ms 26308 KB Output is correct
46 Correct 81 ms 16828 KB Output is correct
47 Correct 89 ms 16848 KB Output is correct
48 Correct 94 ms 16828 KB Output is correct
49 Correct 198 ms 27316 KB Output is correct
50 Correct 94 ms 21692 KB Output is correct
51 Correct 91 ms 16320 KB Output is correct
52 Correct 121 ms 20404 KB Output is correct
53 Correct 122 ms 26548 KB Output is correct
54 Correct 125 ms 27168 KB Output is correct
55 Correct 176 ms 25268 KB Output is correct