답안 #482542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482542 2021-10-25T13:27:39 Z Lam_lai_cuoc_doi Global Warming (CEOI18_glo) C++17
100 / 100
125 ms 5828 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <class T>
void read(T &x)
{
    x = 0;
    register int c;
    while ((c = getchar()) && (c > '9' || c < '0'))
        ;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

constexpr bool typetest = 0;
constexpr int N = 2e5 + 5;
// Obvious: We only increase/decrease prefix or suffix

struct FenwickTree
{
    int n, a[N];
    void Update(int p, int v)
    {
        if (p == 0)
            return;
        for (; p <= n; p += p & -p)
            a[p] = max(a[p], v);
    }
    int Get(int p)
    {
        int ans(0);
        for (; p > 0; p -= p & -p)
            ans = max(ans, a[p]);
        return ans;
    }
} f, g;

int n, m;
ll a[N], x, b[N];

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

void Solve()
{
    sort(b + 1, b + n + 1);
    m = unique(b + 1, b + n + 1) - b - 1;
    f.n = g.n = m;

#define Find(x, v) (lower_bound(x + 1, x + m + 1, v) - x)

    for (int i = 1; i <= n; ++i)
    {
        int u = Find(b, a[i]) - 1,
            v = Find(b, a[i] + x) - 1;

        int p = f.Get(u),
            q = f.Get(v),
            r = g.Get(u);

        f.Update(u + 1, p + 1);
        g.Update(u + 1, max(q, r) + 1);
    }

    cout << g.Get(m);
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("xor.INP", "r"))
    {
        freopen("xor.inp", "r", stdin);
        freopen("xor.out", "w", stdout);
    }
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        // cout << "Case #" << _ << ": ";
        Read();
        Solve();
    }
    // cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

Compilation message

glo.cpp: In function 'void read(T&)':
glo.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     register int c;
      |                  ^
glo.cpp: In function 'int32_t main()':
glo.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen("xor.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen("xor.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 4980 KB Output is correct
2 Correct 104 ms 4992 KB Output is correct
3 Correct 125 ms 4996 KB Output is correct
4 Correct 99 ms 4988 KB Output is correct
5 Correct 59 ms 4196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1472 KB Output is correct
2 Correct 23 ms 1412 KB Output is correct
3 Correct 22 ms 1484 KB Output is correct
4 Correct 18 ms 1228 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 13 ms 1484 KB Output is correct
7 Correct 22 ms 1996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 2680 KB Output is correct
2 Correct 38 ms 2668 KB Output is correct
3 Correct 92 ms 5100 KB Output is correct
4 Correct 57 ms 4184 KB Output is correct
5 Correct 26 ms 3180 KB Output is correct
6 Correct 45 ms 5444 KB Output is correct
7 Correct 48 ms 5404 KB Output is correct
8 Correct 37 ms 3372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 97 ms 4980 KB Output is correct
28 Correct 104 ms 4992 KB Output is correct
29 Correct 125 ms 4996 KB Output is correct
30 Correct 99 ms 4988 KB Output is correct
31 Correct 59 ms 4196 KB Output is correct
32 Correct 26 ms 1472 KB Output is correct
33 Correct 23 ms 1412 KB Output is correct
34 Correct 22 ms 1484 KB Output is correct
35 Correct 18 ms 1228 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 13 ms 1484 KB Output is correct
38 Correct 22 ms 1996 KB Output is correct
39 Correct 40 ms 2680 KB Output is correct
40 Correct 38 ms 2668 KB Output is correct
41 Correct 92 ms 5100 KB Output is correct
42 Correct 57 ms 4184 KB Output is correct
43 Correct 26 ms 3180 KB Output is correct
44 Correct 45 ms 5444 KB Output is correct
45 Correct 48 ms 5404 KB Output is correct
46 Correct 37 ms 3372 KB Output is correct
47 Correct 48 ms 3268 KB Output is correct
48 Correct 48 ms 3320 KB Output is correct
49 Correct 124 ms 5660 KB Output is correct
50 Correct 51 ms 4932 KB Output is correct
51 Correct 42 ms 4072 KB Output is correct
52 Correct 63 ms 5608 KB Output is correct
53 Correct 54 ms 5616 KB Output is correct
54 Correct 61 ms 5684 KB Output is correct
55 Correct 94 ms 5828 KB Output is correct