Submission #89143

# Submission time Handle Problem Language Result Execution time Memory
89143 2018-12-10T14:05:16 Z SpeedOfMagic Global Warming (CEOI18_glo) C++17
100 / 100
1338 ms 77000 KB
/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
using namespace std;
template<typename T> using v = vector<T>;
typedef long long longlong;
//#define int longlong
typedef long double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0  //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt"  : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg)     ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg  arg,Args...  args){put (arg)<<" ";print(args...);}
int getInt(){int a; get a; return a;}
//code goes here
const int N = 524288;
int segTree[N * 2];
void update(int p, int val, int cur = 1, int ll = 1, int rr = N) {
    if (ll == rr) {
        segTree[cur] = max(segTree[cur], val);
        return;
    }
    int mid = (ll + rr) / 2;
    if (p <= mid)
        update(p, val, cur * 2, ll, mid);
    else
        update(p, val, cur * 2 + 1, mid + 1, rr);
    segTree[cur] = max(segTree[cur * 2], segTree[cur * 2 + 1]);
}

int query(int l, int r, int cur = 1, int ll = 1, int rr = N) {
    if (l > r)
        return 0;
    else if (l == ll && r == rr)
        return segTree[cur];
    else {
        int mid = (ll + rr) / 2;
        int res = max(query(l, min(r, mid), cur * 2, ll, mid),
                      query(max(l, mid + 1), r, cur * 2 + 1, mid + 1, rr));
        return res;
    }
}

void run() {
    memset(segTree, 0, sizeof segTree);
    int n, k;
    read(n, k);
    int a[n];
    set<int> d;
    rep(i, 0, n) {
        get a[i];
        d.insert(a[i]);
        d.insert(a[i] - k);
    }
    map<int, int> inv;
    int p = 2;
    for (int j : d)
        inv[j] = p++;

    int v[n];
    rep(i, 0, n)
        v[i] = 1e9 + 1;
    int dp[n][2];
    rep(i, 0, n) {
        dp[i][0] = (lower_bound(v, v + n, a[i]) - v) + 1;
        v[dp[i][0] - 1] = a[i];
        dp[i][1] = query(1, inv[a[i]] - 1) + 1;
        update(inv[a[i] - k], dp[i][0]);
        update(inv[a[i]], dp[i][1]);
    }
    int ans = 0;
    rep(i, 0, n)
        ans = max(ans, dp[i][1]);
    put ans;
}
signed main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); put fixed << setprecision(12); run(); return 0;}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 5 ms 4552 KB Output is correct
3 Correct 6 ms 4552 KB Output is correct
4 Correct 5 ms 4608 KB Output is correct
5 Correct 6 ms 4688 KB Output is correct
6 Correct 5 ms 4692 KB Output is correct
7 Correct 6 ms 4712 KB Output is correct
8 Correct 5 ms 4744 KB Output is correct
9 Correct 5 ms 4744 KB Output is correct
10 Correct 5 ms 4752 KB Output is correct
11 Correct 5 ms 4752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 5 ms 4552 KB Output is correct
3 Correct 6 ms 4552 KB Output is correct
4 Correct 5 ms 4608 KB Output is correct
5 Correct 6 ms 4688 KB Output is correct
6 Correct 5 ms 4692 KB Output is correct
7 Correct 6 ms 4712 KB Output is correct
8 Correct 5 ms 4744 KB Output is correct
9 Correct 5 ms 4744 KB Output is correct
10 Correct 5 ms 4752 KB Output is correct
11 Correct 5 ms 4752 KB Output is correct
12 Correct 6 ms 4780 KB Output is correct
13 Correct 6 ms 4892 KB Output is correct
14 Correct 6 ms 4892 KB Output is correct
15 Correct 5 ms 4892 KB Output is correct
16 Correct 5 ms 4892 KB Output is correct
17 Correct 5 ms 4892 KB Output is correct
18 Correct 6 ms 4892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 5 ms 4552 KB Output is correct
3 Correct 6 ms 4552 KB Output is correct
4 Correct 5 ms 4608 KB Output is correct
5 Correct 6 ms 4688 KB Output is correct
6 Correct 5 ms 4692 KB Output is correct
7 Correct 6 ms 4712 KB Output is correct
8 Correct 5 ms 4744 KB Output is correct
9 Correct 5 ms 4744 KB Output is correct
10 Correct 5 ms 4752 KB Output is correct
11 Correct 5 ms 4752 KB Output is correct
12 Correct 6 ms 4780 KB Output is correct
13 Correct 6 ms 4892 KB Output is correct
14 Correct 6 ms 4892 KB Output is correct
15 Correct 5 ms 4892 KB Output is correct
16 Correct 5 ms 4892 KB Output is correct
17 Correct 5 ms 4892 KB Output is correct
18 Correct 6 ms 4892 KB Output is correct
19 Correct 7 ms 4936 KB Output is correct
20 Correct 7 ms 4948 KB Output is correct
21 Correct 8 ms 4960 KB Output is correct
22 Correct 7 ms 4972 KB Output is correct
23 Correct 8 ms 4984 KB Output is correct
24 Correct 6 ms 4992 KB Output is correct
25 Correct 6 ms 4992 KB Output is correct
26 Correct 6 ms 5004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 811 ms 28696 KB Output is correct
2 Correct 815 ms 30700 KB Output is correct
3 Correct 820 ms 32700 KB Output is correct
4 Correct 811 ms 34644 KB Output is correct
5 Correct 271 ms 34644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 34644 KB Output is correct
2 Correct 189 ms 34644 KB Output is correct
3 Correct 204 ms 34644 KB Output is correct
4 Correct 74 ms 34644 KB Output is correct
5 Correct 6 ms 34644 KB Output is correct
6 Correct 85 ms 34644 KB Output is correct
7 Correct 136 ms 34644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 37720 KB Output is correct
2 Correct 593 ms 38592 KB Output is correct
3 Correct 1338 ms 60804 KB Output is correct
4 Correct 401 ms 60804 KB Output is correct
5 Correct 248 ms 60804 KB Output is correct
6 Correct 506 ms 61788 KB Output is correct
7 Correct 513 ms 63508 KB Output is correct
8 Correct 390 ms 63508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 5 ms 4552 KB Output is correct
3 Correct 6 ms 4552 KB Output is correct
4 Correct 5 ms 4608 KB Output is correct
5 Correct 6 ms 4688 KB Output is correct
6 Correct 5 ms 4692 KB Output is correct
7 Correct 6 ms 4712 KB Output is correct
8 Correct 5 ms 4744 KB Output is correct
9 Correct 5 ms 4744 KB Output is correct
10 Correct 5 ms 4752 KB Output is correct
11 Correct 5 ms 4752 KB Output is correct
12 Correct 6 ms 4780 KB Output is correct
13 Correct 6 ms 4892 KB Output is correct
14 Correct 6 ms 4892 KB Output is correct
15 Correct 5 ms 4892 KB Output is correct
16 Correct 5 ms 4892 KB Output is correct
17 Correct 5 ms 4892 KB Output is correct
18 Correct 6 ms 4892 KB Output is correct
19 Correct 7 ms 4936 KB Output is correct
20 Correct 7 ms 4948 KB Output is correct
21 Correct 8 ms 4960 KB Output is correct
22 Correct 7 ms 4972 KB Output is correct
23 Correct 8 ms 4984 KB Output is correct
24 Correct 6 ms 4992 KB Output is correct
25 Correct 6 ms 4992 KB Output is correct
26 Correct 6 ms 5004 KB Output is correct
27 Correct 811 ms 28696 KB Output is correct
28 Correct 815 ms 30700 KB Output is correct
29 Correct 820 ms 32700 KB Output is correct
30 Correct 811 ms 34644 KB Output is correct
31 Correct 271 ms 34644 KB Output is correct
32 Correct 199 ms 34644 KB Output is correct
33 Correct 189 ms 34644 KB Output is correct
34 Correct 204 ms 34644 KB Output is correct
35 Correct 74 ms 34644 KB Output is correct
36 Correct 6 ms 34644 KB Output is correct
37 Correct 85 ms 34644 KB Output is correct
38 Correct 136 ms 34644 KB Output is correct
39 Correct 581 ms 37720 KB Output is correct
40 Correct 593 ms 38592 KB Output is correct
41 Correct 1338 ms 60804 KB Output is correct
42 Correct 401 ms 60804 KB Output is correct
43 Correct 248 ms 60804 KB Output is correct
44 Correct 506 ms 61788 KB Output is correct
45 Correct 513 ms 63508 KB Output is correct
46 Correct 390 ms 63508 KB Output is correct
47 Correct 459 ms 63508 KB Output is correct
48 Correct 463 ms 63508 KB Output is correct
49 Correct 1036 ms 70524 KB Output is correct
50 Correct 312 ms 70524 KB Output is correct
51 Correct 293 ms 70524 KB Output is correct
52 Correct 397 ms 70524 KB Output is correct
53 Correct 509 ms 74908 KB Output is correct
54 Correct 559 ms 77000 KB Output is correct
55 Correct 630 ms 77000 KB Output is correct