Submission #70964

# Submission time Handle Problem Language Result Execution time Memory
70964 2018-08-23T21:10:52 Z MatheusLealV Global Warming (CEOI18_glo) C++17
100 / 100
1000 ms 171020 KB
#include <bits/stdc++.h>
#define N 200050
#define limite (1000000005)
#define mid ((a + b)/2)
using namespace std;

int n, v[N], dp[N][2], x, resp;

struct node
{
    int val;

    node *l, *r;

    node()
    {
        val = 0;

        l = r = NULL;
    }
};

node *root = new node(), *root1 = new node();

void upd(node *root, int a, int b, int i, int x)
{
    if(a == b)
    {
        root->val = max(root->val, x);

        return;
    }

    if(i <= mid)
    {
        if(!root->l) root->l = new node();

        upd(root->l, a, mid, i, x);
    }

    else
    {
        if(!root->r) root->r = new node();

        upd(root->r, mid + 1, b, i, x);
    }

    root->val = max( (root->l ? root->l->val : 0), (root->r ? root->r->val : 0) );
}

int query(node *root, int a, int b, int i, int j)
{
    if(!root or (j < a or i > b)) return 0;

    if(i <= a and j >= b) return root->val;

    return max(query(root->l, a, mid, i, j), query(root->r, mid + 1, b, i, j));
}

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

    cin>>n>>x;

    for(int i = 1; i <= n; i++) cin>>v[i];

    for(int i = 1; i <= n; i++)
    {
        int A = query(root1, 0, limite, 0, v[i] - 1), B = query(root, 0, limite, 0, v[i] - 1);

        int C = query(root1, 0, limite, v[i], v[i] + x - 1);

        dp[i][1] = A + 1;

        dp[i][0] = max({A, B, C}) + 1;

        resp = max({resp, dp[i][0], dp[i][1]});

        upd(root, 0, limite, v[i], dp[i][0]);

        upd(root1, 0, limite, v[i], dp[i][1]);
    }

    cout<<resp<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 3 ms 720 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 3 ms 720 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 3 ms 720 KB Output is correct
13 Correct 2 ms 720 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 3 ms 720 KB Output is correct
16 Correct 2 ms 720 KB Output is correct
17 Correct 3 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 3 ms 720 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 3 ms 720 KB Output is correct
13 Correct 2 ms 720 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 3 ms 720 KB Output is correct
16 Correct 2 ms 720 KB Output is correct
17 Correct 3 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
19 Correct 7 ms 1892 KB Output is correct
20 Correct 6 ms 1900 KB Output is correct
21 Correct 5 ms 2028 KB Output is correct
22 Correct 6 ms 2028 KB Output is correct
23 Correct 5 ms 2028 KB Output is correct
24 Correct 4 ms 2028 KB Output is correct
25 Correct 4 ms 2028 KB Output is correct
26 Correct 4 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 889 ms 170892 KB Output is correct
2 Correct 878 ms 171008 KB Output is correct
3 Correct 894 ms 171008 KB Output is correct
4 Correct 919 ms 171008 KB Output is correct
5 Correct 404 ms 171008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 171008 KB Output is correct
2 Correct 235 ms 171008 KB Output is correct
3 Correct 238 ms 171008 KB Output is correct
4 Correct 110 ms 171008 KB Output is correct
5 Correct 2 ms 171008 KB Output is correct
6 Correct 92 ms 171008 KB Output is correct
7 Correct 161 ms 171008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 457 ms 171008 KB Output is correct
2 Correct 448 ms 171008 KB Output is correct
3 Correct 935 ms 171020 KB Output is correct
4 Correct 405 ms 171020 KB Output is correct
5 Correct 164 ms 171020 KB Output is correct
6 Correct 293 ms 171020 KB Output is correct
7 Correct 292 ms 171020 KB Output is correct
8 Correct 318 ms 171020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 3 ms 720 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 3 ms 720 KB Output is correct
13 Correct 2 ms 720 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 3 ms 720 KB Output is correct
16 Correct 2 ms 720 KB Output is correct
17 Correct 3 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
19 Correct 7 ms 1892 KB Output is correct
20 Correct 6 ms 1900 KB Output is correct
21 Correct 5 ms 2028 KB Output is correct
22 Correct 6 ms 2028 KB Output is correct
23 Correct 5 ms 2028 KB Output is correct
24 Correct 4 ms 2028 KB Output is correct
25 Correct 4 ms 2028 KB Output is correct
26 Correct 4 ms 2028 KB Output is correct
27 Correct 889 ms 170892 KB Output is correct
28 Correct 878 ms 171008 KB Output is correct
29 Correct 894 ms 171008 KB Output is correct
30 Correct 919 ms 171008 KB Output is correct
31 Correct 404 ms 171008 KB Output is correct
32 Correct 219 ms 171008 KB Output is correct
33 Correct 235 ms 171008 KB Output is correct
34 Correct 238 ms 171008 KB Output is correct
35 Correct 110 ms 171008 KB Output is correct
36 Correct 2 ms 171008 KB Output is correct
37 Correct 92 ms 171008 KB Output is correct
38 Correct 161 ms 171008 KB Output is correct
39 Correct 457 ms 171008 KB Output is correct
40 Correct 448 ms 171008 KB Output is correct
41 Correct 935 ms 171020 KB Output is correct
42 Correct 405 ms 171020 KB Output is correct
43 Correct 164 ms 171020 KB Output is correct
44 Correct 293 ms 171020 KB Output is correct
45 Correct 292 ms 171020 KB Output is correct
46 Correct 318 ms 171020 KB Output is correct
47 Correct 498 ms 171020 KB Output is correct
48 Correct 453 ms 171020 KB Output is correct
49 Correct 1000 ms 171020 KB Output is correct
50 Correct 400 ms 171020 KB Output is correct
51 Correct 224 ms 171020 KB Output is correct
52 Correct 339 ms 171020 KB Output is correct
53 Correct 322 ms 171020 KB Output is correct
54 Correct 328 ms 171020 KB Output is correct
55 Correct 633 ms 171020 KB Output is correct