Submission #658705

# Submission time Handle Problem Language Result Execution time Memory
658705 2022-11-14T13:08:37 Z shrimb Global Warming (CEOI18_glo) C++17
100 / 100
544 ms 174404 KB
#include"bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxa = 2000000000;
const int maxn = 200001;
const int N = exp2(ceil(log2(maxa)));

struct node {
    int Val = 0;
    node *Left = 0, *Right = 0;
};

int Left, Right, Pos, Val;

node *seg, *seg2;

int Query (int l = 1, int r = N, node *ind = seg) {
    if (!ind || l > Right || r < Left) return 0;
    if (l >= Left and r <= Right) return ind -> Val;
    int m = (l + r) / 2;
    return max(Query(l, m, ind -> Left), Query(m + 1, r, ind -> Right));
}

void Update (int l = 1, int r = N, node *ind = seg) {
    if (l > Pos || r < Pos) return;
    if (l == r) {
        ind -> Val = max(ind -> Val, Val);
        return;
    }
    int m = (l + r) / 2;
    if (Pos <= m) {
        if (!ind -> Left) ind -> Left = new node;
        Update(l, m, ind -> Left);
        ind -> Val = max(ind -> Val, ind -> Left -> Val);
    } else {
        if (!ind -> Right) ind -> Right = new node;
        Update(m + 1, r, ind -> Right);
        ind -> Val = max(ind -> Val, ind -> Right -> Val);
    }
}

signed main () {
    cin.tie(0)->sync_with_stdio(0);
    int n, x;
    cin >> n >> x;
    seg = new node;
    seg2 = new node;
    int a[n];
    for (int i = 0 ; i < n ; i++) cin >> a[i];
    int dp[2][n];
    Left = 0;
    int Ans = 0;
    for (int i = 0 ; i < n ; i++) {
        Right = a[i] - 1;
        Val = dp[0][i] = Query() + 1;
        dp[1][i] = Query(1,N,seg2)+1;
        Right = a[i] - 1 + x;
        dp[1][i] = max(dp[1][i], Query() + 1);
        Pos = a[i];
        Update();
        Val = dp[1][i];
        Update(1,N,seg2);
        Ans = max({Ans, dp[0][i], dp[1][i]});
    }
    // for (int i = 0 ; i < n ; i++) cout << dp[0][i] << " " << dp[1][i] << endl;
    cout << Ans << endl;
}

Compilation message

glo.cpp:14:1: warning: multi-line comment [-Wcomment]
   14 | //\
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 3 ms 1620 KB Output is correct
20 Correct 3 ms 1620 KB Output is correct
21 Correct 3 ms 1620 KB Output is correct
22 Correct 3 ms 1616 KB Output is correct
23 Correct 2 ms 960 KB Output is correct
24 Correct 2 ms 980 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 536 ms 174404 KB Output is correct
2 Correct 544 ms 174404 KB Output is correct
3 Correct 519 ms 174348 KB Output is correct
4 Correct 515 ms 174392 KB Output is correct
5 Correct 273 ms 96140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 50036 KB Output is correct
2 Correct 117 ms 50080 KB Output is correct
3 Correct 120 ms 50000 KB Output is correct
4 Correct 71 ms 27316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 52 ms 6404 KB Output is correct
7 Correct 93 ms 36152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 93700 KB Output is correct
2 Correct 245 ms 93616 KB Output is correct
3 Correct 488 ms 174396 KB Output is correct
4 Correct 234 ms 96376 KB Output is correct
5 Correct 99 ms 15744 KB Output is correct
6 Correct 175 ms 29680 KB Output is correct
7 Correct 183 ms 30408 KB Output is correct
8 Correct 176 ms 67880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 3 ms 1620 KB Output is correct
20 Correct 3 ms 1620 KB Output is correct
21 Correct 3 ms 1620 KB Output is correct
22 Correct 3 ms 1616 KB Output is correct
23 Correct 2 ms 960 KB Output is correct
24 Correct 2 ms 980 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 536 ms 174404 KB Output is correct
28 Correct 544 ms 174404 KB Output is correct
29 Correct 519 ms 174348 KB Output is correct
30 Correct 515 ms 174392 KB Output is correct
31 Correct 273 ms 96140 KB Output is correct
32 Correct 120 ms 50036 KB Output is correct
33 Correct 117 ms 50080 KB Output is correct
34 Correct 120 ms 50000 KB Output is correct
35 Correct 71 ms 27316 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 52 ms 6404 KB Output is correct
38 Correct 93 ms 36152 KB Output is correct
39 Correct 254 ms 93700 KB Output is correct
40 Correct 245 ms 93616 KB Output is correct
41 Correct 488 ms 174396 KB Output is correct
42 Correct 234 ms 96376 KB Output is correct
43 Correct 99 ms 15744 KB Output is correct
44 Correct 175 ms 29680 KB Output is correct
45 Correct 183 ms 30408 KB Output is correct
46 Correct 176 ms 67880 KB Output is correct
47 Correct 249 ms 93624 KB Output is correct
48 Correct 256 ms 93592 KB Output is correct
49 Correct 535 ms 174388 KB Output is correct
50 Correct 256 ms 96148 KB Output is correct
51 Correct 138 ms 17204 KB Output is correct
52 Correct 215 ms 31312 KB Output is correct
53 Correct 178 ms 31296 KB Output is correct
54 Correct 240 ms 31984 KB Output is correct
55 Correct 390 ms 127040 KB Output is correct