답안 #866515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866515 2023-10-26T09:47:58 Z 12345678 Global Warming (CEOI18_glo) C++17
100 / 100
145 ms 8788 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=2e5+5;
int n, d, dp[nx], dp2[nx], ans, cnt;
map<int, int> mp;

struct segtree
{
    int d[4*nx];
    void update(int l, int r, int i, int idx, int vl)
    {
        if (idx<l||r<idx) return;
        if (l==r) return void(d[i]=max(d[i], vl));
        int md=(l+r)/2;
        update(l, md, 2*i, idx, vl);
        update(md+1, r, 2*i+1, idx, vl);
        d[i]=max(d[2*i], d[2*i+1]);
    }
    int query(int l, int r, int i, int ql, int qr)
    {
        if (qr<l||r<ql) return INT_MIN;
        if (ql<=l&&r<=qr) return d[i];
        int md=(l+r)/2;
        return max(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr));
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>d;
    vector<int> v(n), vs(n), t;
    for (int i=0; i<n; i++) cin>>v[i], vs[i]=v[i];
    sort(vs.begin(), vs.end());
    for (int i=n-1; i>=0; i--)
    {
        auto itr=lower_bound(t.begin(), t.end(), -v[i]);
        dp[i]=itr-t.begin()+1;
        if (itr==t.end()) t.push_back(-v[i]);
        else *itr=-v[i];
    }
    t.clear();
    for (int i=0; i<n; i++)
    {
        auto itr=lower_bound(t.begin(), t.end(), v[i]);
        dp2[i]=itr-t.begin()+1;
        if (itr==t.end()) t.push_back(v[i]);
        else *itr=v[i];
    }
    for (int i=n-1; i>=0; i--)
    {
        //cout<<v[i]<<' '<<upper_bound(vs.begin(), vs.end(), v[i]-d)-vs.begin()+1<<' '<<lower_bound(vs.begin(), vs.end(), v[i])-vs.begin()+1<<'\n';
        //cout<<"here"<<' '<<dp2[i]<<' '<<s.query(1, n, 1, upper_bound(vs.begin(), vs.end(), v[i]-d)-vs.begin()+1, n)<<'\n';
        ans=max(ans, dp2[i]+s.query(1, n, 1, upper_bound(vs.begin(), vs.end(), v[i]-d)-vs.begin()+1, n));
        s.update(1, n, 1, lower_bound(vs.begin(), vs.end(), v[i])-vs.begin()+1, dp[i]);
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2548 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 6484 KB Output is correct
2 Correct 141 ms 8480 KB Output is correct
3 Correct 144 ms 8480 KB Output is correct
4 Correct 142 ms 8296 KB Output is correct
5 Correct 63 ms 7060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 3416 KB Output is correct
2 Correct 35 ms 3912 KB Output is correct
3 Correct 34 ms 3932 KB Output is correct
4 Correct 15 ms 3676 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 17 ms 3800 KB Output is correct
7 Correct 26 ms 3868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 4188 KB Output is correct
2 Correct 51 ms 5204 KB Output is correct
3 Correct 106 ms 8272 KB Output is correct
4 Correct 50 ms 7272 KB Output is correct
5 Correct 31 ms 5084 KB Output is correct
6 Correct 51 ms 7892 KB Output is correct
7 Correct 51 ms 8756 KB Output is correct
8 Correct 40 ms 5128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2548 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 145 ms 6484 KB Output is correct
28 Correct 141 ms 8480 KB Output is correct
29 Correct 144 ms 8480 KB Output is correct
30 Correct 142 ms 8296 KB Output is correct
31 Correct 63 ms 7060 KB Output is correct
32 Correct 37 ms 3416 KB Output is correct
33 Correct 35 ms 3912 KB Output is correct
34 Correct 34 ms 3932 KB Output is correct
35 Correct 15 ms 3676 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 17 ms 3800 KB Output is correct
38 Correct 26 ms 3868 KB Output is correct
39 Correct 49 ms 4188 KB Output is correct
40 Correct 51 ms 5204 KB Output is correct
41 Correct 106 ms 8272 KB Output is correct
42 Correct 50 ms 7272 KB Output is correct
43 Correct 31 ms 5084 KB Output is correct
44 Correct 51 ms 7892 KB Output is correct
45 Correct 51 ms 8756 KB Output is correct
46 Correct 40 ms 5128 KB Output is correct
47 Correct 67 ms 5068 KB Output is correct
48 Correct 69 ms 5324 KB Output is correct
49 Correct 141 ms 8276 KB Output is correct
50 Correct 61 ms 7124 KB Output is correct
51 Correct 55 ms 7096 KB Output is correct
52 Correct 83 ms 8336 KB Output is correct
53 Correct 53 ms 8200 KB Output is correct
54 Correct 54 ms 8788 KB Output is correct
55 Correct 115 ms 8276 KB Output is correct