Submission #581368

# Submission time Handle Problem Language Result Execution time Memory
581368 2022-06-22T14:27:55 Z drdilyor Global Warming (CEOI18_glo) C++17
32 / 100
63 ms 6096 KB
#if defined(ONPC) && !defined(_GLIBCXX_ASSERTIONS)
    #define _GLIBCXX_ASSERTIONS
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())

using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K>
using ordered_set = pd::tree<K, pd::null_type, less<int>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T>
using gp_hash_table = pd::gp_hash_table<T...>;//simple using statement gives warnings

const int INF = 1e9;
const ll INFL = 1e18;
const int N = 1e5;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

struct Fenwick {
    int n;
    vi tree;
    Fenwick(int n) : n(n), tree(n) {}
    void set_(int i, int d) {
        for (; i < n; i |= i + 1) tree[i] = max(tree[i], d);
    }
    int max_(int i) {
        i = min(i, n-1);
        int res = 0;
        for (; i >= 0; i = (i & (i+1))-1) res = max(res, tree[i]);
        return res;
    }
};

void compress(vi& a) {
    vi ix(a.size());
    for (int i = 0; i < sz(a); i++) ix[i] = i;
    sort(allit(ix), [&](int i, int j) {
        return a[i] < a[j];
    });
    int prev = -1, key = -1;
    for (int i = 0; i < sz(a); i++) {
        if (a[ix[i]] == prev) {
            a[ix[i]] = key;
        } else {
            prev = a[ix[i]];
            a[ix[i]] = ++key;
        }
    }
}

int solve() {
    int n, x; cin >> n >> x;
    vi a(n); for (auto& i : a) cin >> i;

    compress(a);
    vector<vi> dp(2, vi(n));
    Fenwick tree1(n), tree2(n);

    int res = 0;
    for (int i = 0; i < n; i++) {
        dp[0][i] = tree1.max_(a[i]-1) + 1;
        dp[1][i] = max(tree1.max_(a[i]+x-1), tree2.max_(a[i]-1)) + 1;
        tree1.set_(a[i], dp[0][i]);
        tree2.set_(a[i], dp[1][i]);
    }
    cout << tree2.max_(n-1);
    return 0;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}

Compilation message

glo.cpp: In function 'int solve()':
glo.cpp:70:9: warning: unused variable 'res' [-Wunused-variable]
   70 |     int res = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 4164 KB Output is correct
2 Correct 63 ms 6076 KB Output is correct
3 Correct 62 ms 6072 KB Output is correct
4 Correct 58 ms 6080 KB Output is correct
5 Correct 40 ms 5312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 1296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2264 KB Output is correct
2 Correct 28 ms 3256 KB Output is correct
3 Correct 63 ms 6096 KB Output is correct
4 Correct 41 ms 5312 KB Output is correct
5 Correct 18 ms 2756 KB Output is correct
6 Correct 32 ms 5228 KB Output is correct
7 Correct 37 ms 5828 KB Output is correct
8 Correct 28 ms 3268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -