Submission #116159

# Submission time Handle Problem Language Result Execution time Memory
116159 2019-06-11T03:36:20 Z JohnTitor Global Warming (CEOI18_glo) C++11
100 / 100
58 ms 4340 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Global"
int n, x;
int a[200001];
int l[200001];
vector <int> f;
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    read(x);
    FOR(i, 1, n) read(a[i]);
    f.pb(-1e9);
    FOR(i, 1, n){
        if(a[i]>f.back()){
            l[i]=f.size();
            f.pb(a[i]);
        }
        else{
            l[i]=lower_bound(f.begin(), f.end(), a[i])-f.begin();
            f[l[i]]=min(f[l[i]], a[i]);
        }
    }
    f.clear();
    f.pb(1.5e9);
    int ans=0;
    DFOR(i, n, 1){
        int t=a[i]-x;
        if(t<f.back()) ans=max(ans, (int)(l[i]+f.size()-1));
        else ans=max(ans, (int)(l[i]+lower_bound(f.begin(), f.end(), t, greater<int>())-f.begin()-1));
        if(a[i]<f.back()) f.pb(a[i]);
        else{
            t=lower_bound(f.begin(), f.end(), a[i], greater<int>())-f.begin();
            f[t]=max(f[t], a[i]);
        }
    }
    writeln(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 432 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 432 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 432 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 432 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 1912 KB Output is correct
2 Correct 50 ms 1912 KB Output is correct
3 Correct 58 ms 1892 KB Output is correct
4 Correct 49 ms 1920 KB Output is correct
5 Correct 20 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 768 KB Output is correct
2 Correct 13 ms 768 KB Output is correct
3 Correct 13 ms 768 KB Output is correct
4 Correct 7 ms 936 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 7 ms 1280 KB Output is correct
7 Correct 11 ms 1252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1152 KB Output is correct
2 Correct 21 ms 1152 KB Output is correct
3 Correct 42 ms 1884 KB Output is correct
4 Correct 18 ms 2424 KB Output is correct
5 Correct 10 ms 1408 KB Output is correct
6 Correct 16 ms 2296 KB Output is correct
7 Correct 23 ms 2300 KB Output is correct
8 Correct 18 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 432 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 432 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 51 ms 1912 KB Output is correct
28 Correct 50 ms 1912 KB Output is correct
29 Correct 58 ms 1892 KB Output is correct
30 Correct 49 ms 1920 KB Output is correct
31 Correct 20 ms 2424 KB Output is correct
32 Correct 13 ms 768 KB Output is correct
33 Correct 13 ms 768 KB Output is correct
34 Correct 13 ms 768 KB Output is correct
35 Correct 7 ms 936 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 7 ms 1280 KB Output is correct
38 Correct 11 ms 1252 KB Output is correct
39 Correct 21 ms 1152 KB Output is correct
40 Correct 21 ms 1152 KB Output is correct
41 Correct 42 ms 1884 KB Output is correct
42 Correct 18 ms 2424 KB Output is correct
43 Correct 10 ms 1408 KB Output is correct
44 Correct 16 ms 2296 KB Output is correct
45 Correct 23 ms 2300 KB Output is correct
46 Correct 18 ms 1152 KB Output is correct
47 Correct 26 ms 2048 KB Output is correct
48 Correct 25 ms 2048 KB Output is correct
49 Correct 50 ms 3804 KB Output is correct
50 Correct 20 ms 3704 KB Output is correct
51 Correct 15 ms 2940 KB Output is correct
52 Correct 20 ms 3704 KB Output is correct
53 Correct 17 ms 3704 KB Output is correct
54 Correct 24 ms 4340 KB Output is correct
55 Correct 42 ms 3832 KB Output is correct