답안 #960698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960698 2024-04-11T00:31:36 Z quochuy147 Global Warming (CEOI18_glo) C++14
100 / 100
381 ms 27232 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define all(x) (x).begin() , (x).end()
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define file "name"
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}

const int inf = 1e9;
const ll linf = 1e17;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

int n, d, nt, res;
int a[N];
int x[N];
int st[4 * N];
int pre[N];
map <int, int> m;

void inp()
{
    cin >> n >> d;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        x[i] = a[i];
    }
}

struct segtree {
    int st[4 * N];

    segtree() {}

    void update(int id, int l, int r, int i, int v) {
        if(i < l || r < i) return ;
        if(l == r) return void(st[id] = v);
        int m = (l + r) >> 1;
        update(id << 1, l, m, i, v);
        update(id << 1 | 1, m + 1, r, i, v);
        st[id] = max(st[id << 1], st[id << 1 | 1]);
    }

    int get(int id, int l, int r, int u, int v) {
        if(v < l || r < u) return 0;
        if(l >= u && r <= v) return st[id];
        int m = (l + r) >> 1;
        return max(get(id << 1, l, m, u, v), get(id << 1 | 1, m + 1, r, u, v));
    }
} st1, st2;

void solve()
{
    sort(x + 1, x + n + 1);
    nt = unique(x + 1, x + n + 1) - x - 1;
    for(int i = 1; i <= n; ++i) {
        int id = lower_bound(x + 1, x + nt + 1, a[i]) - x;
        int cnt = st1.get(1, 1, nt, 1, id - 1) + 1;
        st1.update(1, 1, nt, id, cnt);
        pre[i] = m[a[i]];
        m[a[i]] = cnt;
        maximize(res, cnt);
    }
    for(int i = n; i >= 1; --i) {
        int id = lower_bound(x + 1, x + nt + 1, a[i]) - x;
        int cnt = st2.get(1, 1, nt, id + 1, nt) + 1;
        st2.update(1, 1, nt, id, cnt);
        st1.update(1, 1, nt, id, pre[i]);
        id = lower_bound(x + 1, x + nt + 1, a[i] + d) - x - 1;
        cnt += st1.get(1, 1, nt, 1, id);
        maximize(res, cnt);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    freopen(file".inp" , "r" , stdin);
//    freopen(file".out" , "w" , stdout);
    inp();
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8664 KB Output is correct
4 Correct 3 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8664 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 5 ms 8692 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8664 KB Output is correct
4 Correct 3 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8664 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 5 ms 8692 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8664 KB Output is correct
4 Correct 3 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8664 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 5 ms 8692 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 6620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 353 ms 25932 KB Output is correct
2 Correct 350 ms 26992 KB Output is correct
3 Correct 340 ms 27048 KB Output is correct
4 Correct 381 ms 27232 KB Output is correct
5 Correct 136 ms 20492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12108 KB Output is correct
2 Correct 76 ms 10472 KB Output is correct
3 Correct 68 ms 10472 KB Output is correct
4 Correct 31 ms 10320 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 35 ms 8520 KB Output is correct
7 Correct 63 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 16448 KB Output is correct
2 Correct 136 ms 14156 KB Output is correct
3 Correct 353 ms 26816 KB Output is correct
4 Correct 137 ms 20736 KB Output is correct
5 Correct 85 ms 13904 KB Output is correct
6 Correct 157 ms 23620 KB Output is correct
7 Correct 159 ms 23668 KB Output is correct
8 Correct 114 ms 14264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8664 KB Output is correct
4 Correct 3 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8664 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 5 ms 8692 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 6620 KB Output is correct
27 Correct 353 ms 25932 KB Output is correct
28 Correct 350 ms 26992 KB Output is correct
29 Correct 340 ms 27048 KB Output is correct
30 Correct 381 ms 27232 KB Output is correct
31 Correct 136 ms 20492 KB Output is correct
32 Correct 68 ms 12108 KB Output is correct
33 Correct 76 ms 10472 KB Output is correct
34 Correct 68 ms 10472 KB Output is correct
35 Correct 31 ms 10320 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 35 ms 8520 KB Output is correct
38 Correct 63 ms 12120 KB Output is correct
39 Correct 140 ms 16448 KB Output is correct
40 Correct 136 ms 14156 KB Output is correct
41 Correct 353 ms 26816 KB Output is correct
42 Correct 137 ms 20736 KB Output is correct
43 Correct 85 ms 13904 KB Output is correct
44 Correct 157 ms 23620 KB Output is correct
45 Correct 159 ms 23668 KB Output is correct
46 Correct 114 ms 14264 KB Output is correct
47 Correct 184 ms 16068 KB Output is correct
48 Correct 155 ms 16276 KB Output is correct
49 Correct 369 ms 27088 KB Output is correct
50 Correct 151 ms 20536 KB Output is correct
51 Correct 130 ms 19264 KB Output is correct
52 Correct 213 ms 25300 KB Output is correct
53 Correct 162 ms 26352 KB Output is correct
54 Correct 168 ms 26196 KB Output is correct
55 Correct 265 ms 27072 KB Output is correct