답안 #1079502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079502 2024-08-28T15:53:31 Z Icelast Global Warming (CEOI18_glo) C++17
100 / 100
879 ms 176716 KB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
struct PersistentSegmentTree{
    struct Node{
        int mx = 0;
        int ln = 0, rn = 0;
    };
    int n, N;
    vector<Node> nodes;
    vector<int> ver;
    PersistentSegmentTree(int n): n(n){
        N = n;
        nodes.push_back({0, 0, 0});
        ver.push_back(0);
    };
    void upd(int &node, int ori, int i, int x){
         auto upd = [&](auto upd, int &node, int ori, int low, int high, int i, int x) -> void{
            node = nodes.size();
            nodes.push_back(nodes[ori]);
            if(low == high){
                nodes[node].mx = max(nodes[node].mx, x);
                return;
            }
            int mid = (low+high)/2;
            Node goat = nodes[node];
            if(i <= mid){
                upd(upd, goat.ln, nodes[ori].ln, low, mid, i, x);
            }else{
                upd(upd, goat.rn, nodes[ori].rn, mid+1, high, i, x);
            }
            goat.mx = max(nodes[goat.ln].mx, nodes[goat.rn].mx);
            nodes[node] = goat;
        };
        upd(upd, node, ori, 1, N, i, x);
    }
    int get_max(int node, int l, int r){
        if(r > 1e9) r = 1e9;
        auto get_max = [&](auto get_max, int node, int low, int high, int l, int r) -> int{
            if(low > r || l > high){
                return 0;
            }
            if(low >= l && r >= high){
                return nodes[node].mx;
            }
            int mid = (low+high)/2;
            return max(get_max(get_max, nodes[node].ln, low, mid, l, r), get_max(get_max, nodes[node].rn, mid+1, high, l, r));
        };
        return get_max(get_max, node, 1, N, l, r);
    }
};

void solve(){
    ll n, x;
    ll B = 1e9+1;
    cin >> n >> x;
    vector<ll> a(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    PersistentSegmentTree Tl(B), Tr(B);
    Tl.ver.resize(n+1, 0);
    Tr.ver.resize(n+1, 0);
    int j = 0;
    for(int i = n; i >= 1; i--){
        j++;
        ll mx = Tr.get_max(Tr.ver[j-1], a[i]+1, B-1)+1;
        Tr.upd(Tr.ver[j], Tr.ver[j-1], a[i], mx);
    }
    j = n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        j--;
        ll mx = Tl.get_max(Tl.ver[i-1], 1, a[i]-1)+1;
        Tl.upd(Tl.ver[i], Tl.ver[i-1], a[i], mx);
        ans = max(ans, Tl.get_max(Tl.ver[i], a[i], a[i])+Tr.get_max(Tr.ver[j], a[i]-x+1, a[i]+x-1));
    }
    cout << ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 1368 KB Output is correct
20 Correct 4 ms 1368 KB Output is correct
21 Correct 5 ms 1368 KB Output is correct
22 Correct 4 ms 1232 KB Output is correct
23 Correct 3 ms 1364 KB Output is correct
24 Correct 3 ms 1368 KB Output is correct
25 Correct 3 ms 1328 KB Output is correct
26 Correct 3 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 850 ms 176660 KB Output is correct
2 Correct 879 ms 176716 KB Output is correct
3 Correct 822 ms 176584 KB Output is correct
4 Correct 805 ms 176536 KB Output is correct
5 Correct 530 ms 176076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 56712 KB Output is correct
2 Correct 172 ms 56576 KB Output is correct
3 Correct 188 ms 56712 KB Output is correct
4 Correct 137 ms 56456 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 141 ms 56688 KB Output is correct
7 Correct 168 ms 56888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 112988 KB Output is correct
2 Correct 342 ms 113300 KB Output is correct
3 Correct 672 ms 176656 KB Output is correct
4 Correct 532 ms 175892 KB Output is correct
5 Correct 272 ms 112732 KB Output is correct
6 Correct 474 ms 172004 KB Output is correct
7 Correct 463 ms 172808 KB Output is correct
8 Correct 283 ms 112984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 1368 KB Output is correct
20 Correct 4 ms 1368 KB Output is correct
21 Correct 5 ms 1368 KB Output is correct
22 Correct 4 ms 1232 KB Output is correct
23 Correct 3 ms 1364 KB Output is correct
24 Correct 3 ms 1368 KB Output is correct
25 Correct 3 ms 1328 KB Output is correct
26 Correct 3 ms 1368 KB Output is correct
27 Correct 850 ms 176660 KB Output is correct
28 Correct 879 ms 176716 KB Output is correct
29 Correct 822 ms 176584 KB Output is correct
30 Correct 805 ms 176536 KB Output is correct
31 Correct 530 ms 176076 KB Output is correct
32 Correct 173 ms 56712 KB Output is correct
33 Correct 172 ms 56576 KB Output is correct
34 Correct 188 ms 56712 KB Output is correct
35 Correct 137 ms 56456 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 141 ms 56688 KB Output is correct
38 Correct 168 ms 56888 KB Output is correct
39 Correct 360 ms 112988 KB Output is correct
40 Correct 342 ms 113300 KB Output is correct
41 Correct 672 ms 176656 KB Output is correct
42 Correct 532 ms 175892 KB Output is correct
43 Correct 272 ms 112732 KB Output is correct
44 Correct 474 ms 172004 KB Output is correct
45 Correct 463 ms 172808 KB Output is correct
46 Correct 283 ms 112984 KB Output is correct
47 Correct 387 ms 112984 KB Output is correct
48 Correct 389 ms 112980 KB Output is correct
49 Correct 816 ms 176644 KB Output is correct
50 Correct 539 ms 175964 KB Output is correct
51 Correct 427 ms 156692 KB Output is correct
52 Correct 579 ms 175888 KB Output is correct
53 Correct 518 ms 175900 KB Output is correct
54 Correct 563 ms 176708 KB Output is correct
55 Correct 666 ms 176656 KB Output is correct