답안 #1096314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096314 2024-10-04T09:22:23 Z Wewoo Global Warming (CEOI18_glo) C++17
100 / 100
63 ms 10068 KB
#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;

const int MAXN = 2e5 + 105;
typedef pair <int, int> ii;

int n, x;
int a[2 * MAXN + 10];
ii b[2 * MAXN + 10];

namespace Sub1
{
    int lis[MAXN + 5];
    void Solve()
    {
        int len = 0;
        for (int i = 1; i <= n; ++i)
        {
            int idx = lower_bound(lis + 1, lis + len + 1, a[i]) - lis;
            lis[idx] = a[i];
            len = max(len, idx);
        }

        cout << len;
    }
}

namespace Sub2
{
    int bitMax[2][2 * MAXN + 10];
    void Update(int bitMax[], int idx, int val)
    {
        for (int i = idx; i <= 2 * n; i += i & (-i))
            bitMax[i] = max(bitMax[i], val);
    }

    int getMax(int bitMax[], int idx)
    {
        int ans = 0;
        for (int i = idx; 0 < i; i -= i & (-i))
            ans = max(ans, bitMax[i]);
        return ans;
    }

    void Solve()
    {
        for (int i = 1; i <= n; ++i)
        {
            cin >> a[i];
            b[i].F = a[i]; b[i].S = i;
            b[n + i].F = a[i] + x, b[n + i].S = n + i;
        }

        sort(b + 1, b + 2 * n + 1);
        for (int i = 1; i <= 2 * n; ++i)
        {
            a[b[i].S] = a[b[i - 1].S] + (b[i - 1].F < b[i].F);
        }

        int res = 0;
        for (int i = 1; i <= n; ++i)
        {
            int val1 = getMax(bitMax[0], a[i] - 1) + 1;
            int val2 = getMax(bitMax[0], a[n + i] - 1) + 1;
            int val3 = getMax(bitMax[1], a[i] - 1) + 1;

            Update(bitMax[0], a[i], val1);
            Update(bitMax[1], a[i], max(val2, val3));

            res = max(max(res, val1), max(val2, val3));
        }

        cout << res;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> x;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    if (x == 0) Sub1::Solve(); else Sub2::Solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 3188 KB Output is correct
2 Correct 24 ms 2924 KB Output is correct
3 Correct 22 ms 3160 KB Output is correct
4 Correct 26 ms 3424 KB Output is correct
5 Correct 13 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2908 KB Output is correct
2 Correct 14 ms 2712 KB Output is correct
3 Correct 14 ms 2712 KB Output is correct
4 Correct 11 ms 2380 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 13 ms 2256 KB Output is correct
7 Correct 13 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 4444 KB Output is correct
2 Correct 29 ms 4440 KB Output is correct
3 Correct 63 ms 8528 KB Output is correct
4 Correct 52 ms 6992 KB Output is correct
5 Correct 16 ms 4188 KB Output is correct
6 Correct 34 ms 7508 KB Output is correct
7 Correct 38 ms 8240 KB Output is correct
8 Correct 25 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 24 ms 3188 KB Output is correct
28 Correct 24 ms 2924 KB Output is correct
29 Correct 22 ms 3160 KB Output is correct
30 Correct 26 ms 3424 KB Output is correct
31 Correct 13 ms 2636 KB Output is correct
32 Correct 14 ms 2908 KB Output is correct
33 Correct 14 ms 2712 KB Output is correct
34 Correct 14 ms 2712 KB Output is correct
35 Correct 11 ms 2380 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 13 ms 2256 KB Output is correct
38 Correct 13 ms 2652 KB Output is correct
39 Correct 28 ms 4444 KB Output is correct
40 Correct 29 ms 4440 KB Output is correct
41 Correct 63 ms 8528 KB Output is correct
42 Correct 52 ms 6992 KB Output is correct
43 Correct 16 ms 4188 KB Output is correct
44 Correct 34 ms 7508 KB Output is correct
45 Correct 38 ms 8240 KB Output is correct
46 Correct 25 ms 4432 KB Output is correct
47 Correct 35 ms 5104 KB Output is correct
48 Correct 29 ms 5200 KB Output is correct
49 Correct 60 ms 10068 KB Output is correct
50 Correct 44 ms 7756 KB Output is correct
51 Correct 34 ms 5544 KB Output is correct
52 Correct 44 ms 7764 KB Output is correct
53 Correct 36 ms 7764 KB Output is correct
54 Correct 40 ms 8628 KB Output is correct
55 Correct 55 ms 9556 KB Output is correct