Submission #216800

# Submission time Handle Problem Language Result Execution time Memory
216800 2020-03-28T04:53:27 Z DystoriaX Global Warming (CEOI18_glo) C++14
100 / 100
183 ms 5496 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 2e5 + 10;

class BIT{
private:
    vector<int> bit;

public:
    void update(int x, int val){
        for(; x < MAX; x += x & (-x)) bit[x] = max(bit[x], val);
    }

    int query(int x){
        int ret = 0;
        for(; x; x -= x & (-x)) ret = max(ret, bit[x]);

        return ret;
    }

    BIT(){
        bit.assign(MAX, 0);
    }
};

int n, x;
int a[200010];
vector<int> cmp;
int ans;
BIT dp[2];

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

    cmp.resize(n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]), cmp[i - 1] = a[i];

    sort(cmp.begin(), cmp.end());
    cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());

    for(int i = 1; i <= n; i++){
        auto id1 = upper_bound(cmp.begin(), cmp.end(), a[i] - 1) - cmp.begin();
        auto id2 = upper_bound(cmp.begin(), cmp.end(), a[i] + x - 1) - cmp.begin();
        auto id = upper_bound(cmp.begin(), cmp.end(), a[i]) - cmp.begin();

        int val1 = dp[1].query(id1) + 1;
        int val2 = dp[0].query(id2) + 1;

        dp[0].update(id, dp[0].query(id1) + 1);
        dp[1].update(id, max(val1, val2));
    }

    printf("%d\n", dp[1].query(MAX - 1));
    
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &x);
     ~~~~~^~~~~~~~~~~~~~~~
glo.cpp:38:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", &a[i]), cmp[i - 1] = a[i];
                                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1920 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
3 Correct 5 ms 1920 KB Output is correct
4 Correct 5 ms 1920 KB Output is correct
5 Correct 6 ms 1920 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 8 ms 1920 KB Output is correct
8 Correct 5 ms 1920 KB Output is correct
9 Correct 6 ms 1920 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1920 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
3 Correct 5 ms 1920 KB Output is correct
4 Correct 5 ms 1920 KB Output is correct
5 Correct 6 ms 1920 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 8 ms 1920 KB Output is correct
8 Correct 5 ms 1920 KB Output is correct
9 Correct 6 ms 1920 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 6 ms 1920 KB Output is correct
14 Correct 6 ms 1920 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 6 ms 1920 KB Output is correct
17 Correct 6 ms 1920 KB Output is correct
18 Correct 6 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1920 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
3 Correct 5 ms 1920 KB Output is correct
4 Correct 5 ms 1920 KB Output is correct
5 Correct 6 ms 1920 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 8 ms 1920 KB Output is correct
8 Correct 5 ms 1920 KB Output is correct
9 Correct 6 ms 1920 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 6 ms 1920 KB Output is correct
14 Correct 6 ms 1920 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 6 ms 1920 KB Output is correct
17 Correct 6 ms 1920 KB Output is correct
18 Correct 6 ms 1920 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 6 ms 1920 KB Output is correct
21 Correct 6 ms 1920 KB Output is correct
22 Correct 6 ms 1920 KB Output is correct
23 Correct 6 ms 1920 KB Output is correct
24 Correct 6 ms 1920 KB Output is correct
25 Correct 6 ms 1920 KB Output is correct
26 Correct 6 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 3448 KB Output is correct
2 Correct 183 ms 5496 KB Output is correct
3 Correct 161 ms 5496 KB Output is correct
4 Correct 159 ms 5368 KB Output is correct
5 Correct 83 ms 4604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2304 KB Output is correct
2 Correct 41 ms 2816 KB Output is correct
3 Correct 42 ms 2816 KB Output is correct
4 Correct 25 ms 2560 KB Output is correct
5 Correct 6 ms 1920 KB Output is correct
6 Correct 24 ms 2560 KB Output is correct
7 Correct 35 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 2808 KB Output is correct
2 Correct 69 ms 3712 KB Output is correct
3 Correct 146 ms 5368 KB Output is correct
4 Correct 79 ms 4600 KB Output is correct
5 Correct 46 ms 3320 KB Output is correct
6 Correct 74 ms 4608 KB Output is correct
7 Correct 81 ms 5240 KB Output is correct
8 Correct 59 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1920 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
3 Correct 5 ms 1920 KB Output is correct
4 Correct 5 ms 1920 KB Output is correct
5 Correct 6 ms 1920 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 8 ms 1920 KB Output is correct
8 Correct 5 ms 1920 KB Output is correct
9 Correct 6 ms 1920 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 6 ms 1920 KB Output is correct
14 Correct 6 ms 1920 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 6 ms 1920 KB Output is correct
17 Correct 6 ms 1920 KB Output is correct
18 Correct 6 ms 1920 KB Output is correct
19 Correct 6 ms 1920 KB Output is correct
20 Correct 6 ms 1920 KB Output is correct
21 Correct 6 ms 1920 KB Output is correct
22 Correct 6 ms 1920 KB Output is correct
23 Correct 6 ms 1920 KB Output is correct
24 Correct 6 ms 1920 KB Output is correct
25 Correct 6 ms 1920 KB Output is correct
26 Correct 6 ms 1920 KB Output is correct
27 Correct 157 ms 3448 KB Output is correct
28 Correct 183 ms 5496 KB Output is correct
29 Correct 161 ms 5496 KB Output is correct
30 Correct 159 ms 5368 KB Output is correct
31 Correct 83 ms 4604 KB Output is correct
32 Correct 45 ms 2304 KB Output is correct
33 Correct 41 ms 2816 KB Output is correct
34 Correct 42 ms 2816 KB Output is correct
35 Correct 25 ms 2560 KB Output is correct
36 Correct 6 ms 1920 KB Output is correct
37 Correct 24 ms 2560 KB Output is correct
38 Correct 35 ms 2816 KB Output is correct
39 Correct 70 ms 2808 KB Output is correct
40 Correct 69 ms 3712 KB Output is correct
41 Correct 146 ms 5368 KB Output is correct
42 Correct 79 ms 4600 KB Output is correct
43 Correct 46 ms 3320 KB Output is correct
44 Correct 74 ms 4608 KB Output is correct
45 Correct 81 ms 5240 KB Output is correct
46 Correct 59 ms 3712 KB Output is correct
47 Correct 80 ms 3704 KB Output is correct
48 Correct 79 ms 3708 KB Output is correct
49 Correct 168 ms 5368 KB Output is correct
50 Correct 87 ms 4608 KB Output is correct
51 Correct 72 ms 3968 KB Output is correct
52 Correct 110 ms 4728 KB Output is correct
53 Correct 85 ms 4984 KB Output is correct
54 Correct 93 ms 5496 KB Output is correct
55 Correct 136 ms 5368 KB Output is correct