Submission #77916

# Submission time Handle Problem Language Result Execution time Memory
77916 2018-10-01T07:39:43 Z Saboon Global Warming (CEOI18_glo) C++14
100 / 100
169 ms 29788 KB
#include <iostream>
#include <queue>
#include <bitset>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef unsigned long long ull;

const int inf = 1e9 + 100;
const int maxn = 2e5 + 100;

int fen[2][2 * maxn];

int dp[maxn][2], a[maxn];

void change (int idx, int val1, int val2) {
    for (; idx < 2 * maxn; idx += idx & -idx) {
        fen[0][idx] = max (fen[0][idx], val1);
        fen[1][idx] = max (fen[1][idx], val2);
    }
}

int get (int idx, bool wh) {
    int ret = 0;
    for (; idx > 0; idx -= idx & -idx)
        ret = max (ret, fen[wh][idx]);
    return ret;
}

int n, x;

int nex[2 * maxn];

vector <int> v;
void compress () {
    for (int i = 0; i < n; i++) {
        v.PB (a[i]);
        v.PB (a[i] + x);
    }
    sort (v.begin(), v.end());
    v.resize (unique (v.begin(), v.end()) - v.begin());
    for (int i = 0; i < n; i++) {
        int tmp = a[i];
        a[i] = lower_bound (v.begin(), v.end(), a[i]) - v.begin() + 1;
        nex[a[i]] = lower_bound (v.begin(), v.end(), tmp + x) - v.begin() + 1;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> x;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    compress ();
    dp[0][0] = 1;
    dp[0][1] = 1;
    int ans = 1;
    change (a[0], dp[0][0], dp[0][1]);
    for (int i = 1; i < n; i++) {
        dp[i][0] = get (a[i] - 1, 0) + 1;
        dp[i][1] = get (nex[a[i]] - 1, 0) + 1;
        dp[i][1] = max (dp[i][1], get (a[i] - 1, 1) + 1);
        change (a[i], dp[i][0], dp[i][1]);
        ans = max (ans, dp[i][1]);
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 7020 KB Output is correct
2 Correct 151 ms 8920 KB Output is correct
3 Correct 147 ms 10856 KB Output is correct
4 Correct 155 ms 12780 KB Output is correct
5 Correct 75 ms 12856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 12856 KB Output is correct
2 Correct 43 ms 12856 KB Output is correct
3 Correct 37 ms 12856 KB Output is correct
4 Correct 20 ms 12856 KB Output is correct
5 Correct 2 ms 12856 KB Output is correct
6 Correct 20 ms 12856 KB Output is correct
7 Correct 32 ms 12856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 12856 KB Output is correct
2 Correct 82 ms 12856 KB Output is correct
3 Correct 169 ms 16832 KB Output is correct
4 Correct 87 ms 16840 KB Output is correct
5 Correct 49 ms 16840 KB Output is correct
6 Correct 86 ms 19480 KB Output is correct
7 Correct 87 ms 21300 KB Output is correct
8 Correct 63 ms 21300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 764 KB Output is correct
27 Correct 148 ms 7020 KB Output is correct
28 Correct 151 ms 8920 KB Output is correct
29 Correct 147 ms 10856 KB Output is correct
30 Correct 155 ms 12780 KB Output is correct
31 Correct 75 ms 12856 KB Output is correct
32 Correct 37 ms 12856 KB Output is correct
33 Correct 43 ms 12856 KB Output is correct
34 Correct 37 ms 12856 KB Output is correct
35 Correct 20 ms 12856 KB Output is correct
36 Correct 2 ms 12856 KB Output is correct
37 Correct 20 ms 12856 KB Output is correct
38 Correct 32 ms 12856 KB Output is correct
39 Correct 79 ms 12856 KB Output is correct
40 Correct 82 ms 12856 KB Output is correct
41 Correct 169 ms 16832 KB Output is correct
42 Correct 87 ms 16840 KB Output is correct
43 Correct 49 ms 16840 KB Output is correct
44 Correct 86 ms 19480 KB Output is correct
45 Correct 87 ms 21300 KB Output is correct
46 Correct 63 ms 21300 KB Output is correct
47 Correct 78 ms 21588 KB Output is correct
48 Correct 77 ms 22600 KB Output is correct
49 Correct 163 ms 28748 KB Output is correct
50 Correct 78 ms 28748 KB Output is correct
51 Correct 62 ms 28748 KB Output is correct
52 Correct 88 ms 28748 KB Output is correct
53 Correct 86 ms 28748 KB Output is correct
54 Correct 95 ms 28748 KB Output is correct
55 Correct 130 ms 29788 KB Output is correct