답안 #516461

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516461 2022-01-21T11:12:37 Z Jomnoi Global Warming (CEOI18_glo) C++17
100 / 100
771 ms 54068 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int MX = 2e5 + 10;

int t[MX];
int dp1[MX], dp2[MX];

class SegmentTree {
    protected :
        const int N;
        vector <int> tree;
    public :
        SegmentTree(const int &n) : N(n) {
            tree.resize(4 * N, 0);
        }

        void update(const int &idx, const int &l, const int &r, const int &q, const int &k) {
            if(r < q or q < l) {
                return;
            }
            if(l == r) {
                tree[idx] = max(tree[idx], k);
                return;
            }

            int mid = (l + r) / 2;
            update(idx * 2, l, mid, q, k);
            update(idx * 2 + 1, mid + 1, r, q, k);
            tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]);
        }

        int query(const int &idx, const int &l, const int &r, const int &ql, const int &qr) {
            if(r < ql or qr < l) {
                return 0;
            }
            if(ql <= l and r <= qr) {
                return tree[idx];
            }

            int mid = (l + r) / 2;
            return max(query(idx * 2, l, mid, ql, qr), query(idx * 2 + 1, mid + 1, r, ql, qr));
        }
};

int main() {
    int n, x;
    scanf(" %d %d", &n, &x);

    set <int> s;
    unordered_map <int, int> mp;
    for(int i = 1; i <= n; i++) {
        scanf(" %d", &t[i]);
        s.insert(t[i]);
        s.insert(t[i] - x);
    }

    int cnt = 0;
    for(auto v : s) {
        mp[v] = ++cnt;
    }

    SegmentTree st1(cnt), st2(cnt);
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        dp1[i] = st1.query(1, 1, cnt, 1, mp[t[i]] - 1) + 1;
        dp2[i] = st2.query(1, 1, cnt, 1, mp[t[i]] - 1) + 1;
        st1.update(1, 1, cnt, mp[t[i]], dp1[i]);
        st2.update(1, 1, cnt, mp[t[i]], dp2[i]);
        st2.update(1, 1, cnt, mp[t[i] - x], dp1[i]);
        ans = max(ans, max(dp1[i], dp2[i]));
    }
    printf("%d", ans);
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf(" %d %d", &n, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
glo.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf(" %d", &t[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 292 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 292 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 292 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 428 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 445 ms 29120 KB Output is correct
2 Correct 437 ms 29192 KB Output is correct
3 Correct 475 ms 29128 KB Output is correct
4 Correct 485 ms 29244 KB Output is correct
5 Correct 219 ms 16052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 13644 KB Output is correct
2 Correct 107 ms 13660 KB Output is correct
3 Correct 142 ms 13636 KB Output is correct
4 Correct 67 ms 7248 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 61 ms 7288 KB Output is correct
7 Correct 82 ms 11076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 27112 KB Output is correct
2 Correct 307 ms 27020 KB Output is correct
3 Correct 771 ms 53964 KB Output is correct
4 Correct 330 ms 28480 KB Output is correct
5 Correct 158 ms 26808 KB Output is correct
6 Correct 321 ms 50908 KB Output is correct
7 Correct 330 ms 51584 KB Output is correct
8 Correct 277 ms 27044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 292 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 428 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 445 ms 29120 KB Output is correct
28 Correct 437 ms 29192 KB Output is correct
29 Correct 475 ms 29128 KB Output is correct
30 Correct 485 ms 29244 KB Output is correct
31 Correct 219 ms 16052 KB Output is correct
32 Correct 112 ms 13644 KB Output is correct
33 Correct 107 ms 13660 KB Output is correct
34 Correct 142 ms 13636 KB Output is correct
35 Correct 67 ms 7248 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 61 ms 7288 KB Output is correct
38 Correct 82 ms 11076 KB Output is correct
39 Correct 345 ms 27112 KB Output is correct
40 Correct 307 ms 27020 KB Output is correct
41 Correct 771 ms 53964 KB Output is correct
42 Correct 330 ms 28480 KB Output is correct
43 Correct 158 ms 26808 KB Output is correct
44 Correct 321 ms 50908 KB Output is correct
45 Correct 330 ms 51584 KB Output is correct
46 Correct 277 ms 27044 KB Output is correct
47 Correct 284 ms 27164 KB Output is correct
48 Correct 323 ms 27092 KB Output is correct
49 Correct 708 ms 53960 KB Output is correct
50 Correct 269 ms 28376 KB Output is correct
51 Correct 211 ms 20612 KB Output is correct
52 Correct 259 ms 28652 KB Output is correct
53 Correct 340 ms 53288 KB Output is correct
54 Correct 355 ms 54068 KB Output is correct
55 Correct 467 ms 43860 KB Output is correct