답안 #671742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671742 2022-12-13T15:55:57 Z LittleCube Global Warming (CEOI18_glo) C++14
100 / 100
175 ms 8008 KB
#include <bits/stdc++.h>
#define ll long long
#define plll tuple<ll, ll, ll>
using namespace std;

int n, d, a[200005], b[200005], bit[400005], dp[200005][2];

void modify(int pos, int val)
{
    for (int i = pos; i <= 2 * n; i += (i & -i))
        bit[i] = max(bit[i], val);
}

int query(int pos)
{
    int res = 0;
    for (int i = pos; i > 0; i -= (i & -i))
        res = max(res, bit[i]);
    return res;
}

signed main()
{
    cin >> n >> d;
    vector<int> v;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        v.emplace_back(a[i]);
        v.emplace_back(a[i] + d);
    }
    sort(v.begin(), v.end());
    for (int i = 1; i <= n; i++)
    {
        b[i] = lower_bound(v.begin(), v.end(), a[i] + d) - v.begin() + 1;
        a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
    }
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = query(a[i] - 1) + 1;
        modify(a[i], dp[i][0]);
    }
    for (int i = 1; i <= 2 * n; i++)
        bit[i] = 0;
    for (int i = 1; i <= n; i++)
    {
        dp[i][1] = query(b[i] - 1) + 1;
        modify(a[i], dp[i][0]);
        modify(b[i], dp[i][1]);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans = max({ans, dp[i][0], dp[i][1]});
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 7068 KB Output is correct
2 Correct 167 ms 6740 KB Output is correct
3 Correct 162 ms 6676 KB Output is correct
4 Correct 164 ms 6588 KB Output is correct
5 Correct 95 ms 6588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2444 KB Output is correct
2 Correct 38 ms 1960 KB Output is correct
3 Correct 39 ms 1924 KB Output is correct
4 Correct 25 ms 1988 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 24 ms 2244 KB Output is correct
7 Correct 36 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 4028 KB Output is correct
2 Correct 87 ms 3504 KB Output is correct
3 Correct 175 ms 6664 KB Output is correct
4 Correct 102 ms 6584 KB Output is correct
5 Correct 54 ms 3544 KB Output is correct
6 Correct 98 ms 6300 KB Output is correct
7 Correct 115 ms 6364 KB Output is correct
8 Correct 74 ms 3548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 172 ms 7068 KB Output is correct
28 Correct 167 ms 6740 KB Output is correct
29 Correct 162 ms 6676 KB Output is correct
30 Correct 164 ms 6588 KB Output is correct
31 Correct 95 ms 6588 KB Output is correct
32 Correct 41 ms 2444 KB Output is correct
33 Correct 38 ms 1960 KB Output is correct
34 Correct 39 ms 1924 KB Output is correct
35 Correct 25 ms 1988 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 24 ms 2244 KB Output is correct
38 Correct 36 ms 2432 KB Output is correct
39 Correct 86 ms 4028 KB Output is correct
40 Correct 87 ms 3504 KB Output is correct
41 Correct 175 ms 6664 KB Output is correct
42 Correct 102 ms 6584 KB Output is correct
43 Correct 54 ms 3544 KB Output is correct
44 Correct 98 ms 6300 KB Output is correct
45 Correct 115 ms 6364 KB Output is correct
46 Correct 74 ms 3548 KB Output is correct
47 Correct 80 ms 4500 KB Output is correct
48 Correct 80 ms 4484 KB Output is correct
49 Correct 170 ms 7880 KB Output is correct
50 Correct 95 ms 7816 KB Output is correct
51 Correct 78 ms 5900 KB Output is correct
52 Correct 106 ms 7864 KB Output is correct
53 Correct 100 ms 7900 KB Output is correct
54 Correct 120 ms 8008 KB Output is correct
55 Correct 157 ms 7928 KB Output is correct