답안 #923722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923722 2024-02-07T16:01:17 Z asdasdqwer Global Warming (CEOI18_glo) C++14
100 / 100
96 ms 9784 KB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t

signed main() {
    int n,k;cin>>n>>k;
    vector<int> a(n);
    for (int &x:a)cin>>x;

    vector<int> tmp;
    // different types of operations
    // 1. appended element to array: op.top()[0] == 0
    // 2. changed element at index i: op.top()[0] == 1, op.top()[1] == i, op.top()[2] == oldValue
    stack<array<int,3>> op;
    function<int(int)> bns1=[&](int mx) -> int {
        if (tmp.size() == 0) return -1;
        int l = 0, r = tmp.size() - 1;
        int ans = -1;

        while (l <= r) {
            int m = l + (r-l)/2;
            if (tmp[m] <= mx) {
                ans = m;
                r = m-1;
            }

            else {
                l = m+1;
            }
        }
        return ans;
    };

    for (int i=n-1;i>=0;i--) {
        int idx = bns1(a[i]);
        if (idx == -1) {
            tmp.push_back(a[i]);
            op.push({0, 0, 0});
        }

        else {
            op.push({1, idx, tmp[idx]});
            tmp[idx] = a[i];
        }
    }

    int cand = tmp.size();
    for (int i=0;i<n;i++) {
        a[i] -= k;
    }

    vector<int> lis;

    function<void(array<int,3>)> undo=[&](array<int,3> ope) {
        if (ope[0] == 0) {
            tmp.pop_back();
        }

        else {
            tmp[ope[1]] = ope[2];
        }
    };

    undo(op.top());
    op.pop();

    function<int(int)> bns2=[&](int mx) -> int {
        if (tmp[0] <= mx) return -1;

        int l = 0, r = tmp.size() - 1;
        int ans = -1;

        while (l <= r) {
            int m = l + (r-l)/2;
            if (tmp[m] > mx) {
                ans = m;
                l = m+1;
            }

            else {
                r = m-1;
            }
        }

        return ans;
    };

    for (int i=0;i<n-1;i++) {
        int idx;
        auto it = lower_bound(lis.begin(), lis.end(), a[i]);

        if (it == lis.end()) {
            lis.push_back(a[i]);
            idx = lis.size() - 1;
        }

        else {
            idx = distance(lis.begin(), it);
            lis[idx] = a[i];
        }

        int val = a[i];
        cand = max(cand, idx + 2 + bns2(a[i]));

        undo(op.top());op.pop();
    }

    cout<<cand<<"\n";
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:103:13: warning: unused variable 'val' [-Wunused-variable]
  103 |         int val = a[i];
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 1 ms 356 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 356 KB Output is correct
23 Correct 1 ms 360 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 6852 KB Output is correct
2 Correct 88 ms 8532 KB Output is correct
3 Correct 91 ms 8764 KB Output is correct
4 Correct 91 ms 8792 KB Output is correct
5 Correct 54 ms 8900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1880 KB Output is correct
2 Correct 22 ms 2344 KB Output is correct
3 Correct 22 ms 2388 KB Output is correct
4 Correct 14 ms 2520 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 16 ms 2520 KB Output is correct
7 Correct 20 ms 2556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 3408 KB Output is correct
2 Correct 41 ms 4400 KB Output is correct
3 Correct 82 ms 8532 KB Output is correct
4 Correct 56 ms 8648 KB Output is correct
5 Correct 28 ms 4564 KB Output is correct
6 Correct 52 ms 9324 KB Output is correct
7 Correct 67 ms 8900 KB Output is correct
8 Correct 39 ms 4396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 356 KB Output is correct
17 Correct 0 ms 356 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 1 ms 356 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 356 KB Output is correct
23 Correct 1 ms 360 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 89 ms 6852 KB Output is correct
28 Correct 88 ms 8532 KB Output is correct
29 Correct 91 ms 8764 KB Output is correct
30 Correct 91 ms 8792 KB Output is correct
31 Correct 54 ms 8900 KB Output is correct
32 Correct 22 ms 1880 KB Output is correct
33 Correct 22 ms 2344 KB Output is correct
34 Correct 22 ms 2388 KB Output is correct
35 Correct 14 ms 2520 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 16 ms 2520 KB Output is correct
38 Correct 20 ms 2556 KB Output is correct
39 Correct 41 ms 3408 KB Output is correct
40 Correct 41 ms 4400 KB Output is correct
41 Correct 82 ms 8532 KB Output is correct
42 Correct 56 ms 8648 KB Output is correct
43 Correct 28 ms 4564 KB Output is correct
44 Correct 52 ms 9324 KB Output is correct
45 Correct 67 ms 8900 KB Output is correct
46 Correct 39 ms 4396 KB Output is correct
47 Correct 45 ms 4432 KB Output is correct
48 Correct 44 ms 4436 KB Output is correct
49 Correct 96 ms 8760 KB Output is correct
50 Correct 55 ms 8648 KB Output is correct
51 Correct 46 ms 7164 KB Output is correct
52 Correct 60 ms 8896 KB Output is correct
53 Correct 54 ms 9784 KB Output is correct
54 Correct 71 ms 9412 KB Output is correct
55 Correct 80 ms 8784 KB Output is correct