Submission #299848

# Submission time Handle Problem Language Result Execution time Memory
299848 2020-09-15T20:16:19 Z thomas_li Global Warming (CEOI18_glo) C++17
100 / 100
67 ms 4624 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template<class RIt> void dbarr(RIt frs, RIt lst){ cerr << "arr: "; for(int i = 0; i < (int)(lst-frs); i++) cerr << frs[i] << " \n"[i==(int)(lst-frs)-1]; }
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 2e5+5;
int n,x,a[MM],l[MM],best[MM];
int main(){
    //freopen("in.txt","r", stdin);
	cin.tie(0)->sync_with_stdio(0);
    cin >> n >> x;
    for(int i = 0; i < n; i++) cin >> a[i];
    memset(l,0x3f,sizeof l);
    int ans = 0;
    for(int i = 0; i < n; i++){
        int pos = lower_bound(l,l+n,a[i])-l;
        l[pos] = a[i];
        best[i] = pos+1;
        ans = max(ans,best[i]);
    }
    memset(l,0x3f,sizeof l);
    for(int i = n-1; i >= 0; i--){
        a[i] *= -1;
        int pos = lower_bound(l,l+n,a[i]+x)-l;
        int pos1 = lower_bound(l,l+n,a[i])-l;
        l[pos1] = a[i];
        ans = max(ans,best[i]+pos);
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1184 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1184 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1172 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 1 ms 1152 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1184 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1172 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 1 ms 1152 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 1 ms 1152 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 1 ms 1152 KB Output is correct
24 Correct 1 ms 1152 KB Output is correct
25 Correct 1 ms 1152 KB Output is correct
26 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 4600 KB Output is correct
2 Correct 66 ms 4600 KB Output is correct
3 Correct 66 ms 4604 KB Output is correct
4 Correct 67 ms 4600 KB Output is correct
5 Correct 47 ms 3836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2048 KB Output is correct
2 Correct 16 ms 2048 KB Output is correct
3 Correct 18 ms 2048 KB Output is correct
4 Correct 12 ms 1792 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 12 ms 1792 KB Output is correct
7 Correct 14 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2936 KB Output is correct
2 Correct 32 ms 2944 KB Output is correct
3 Correct 58 ms 4624 KB Output is correct
4 Correct 47 ms 3832 KB Output is correct
5 Correct 24 ms 2552 KB Output is correct
6 Correct 41 ms 3832 KB Output is correct
7 Correct 45 ms 4472 KB Output is correct
8 Correct 25 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1184 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1172 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 1 ms 1152 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 1 ms 1152 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 1 ms 1152 KB Output is correct
24 Correct 1 ms 1152 KB Output is correct
25 Correct 1 ms 1152 KB Output is correct
26 Correct 1 ms 1152 KB Output is correct
27 Correct 66 ms 4600 KB Output is correct
28 Correct 66 ms 4600 KB Output is correct
29 Correct 66 ms 4604 KB Output is correct
30 Correct 67 ms 4600 KB Output is correct
31 Correct 47 ms 3836 KB Output is correct
32 Correct 16 ms 2048 KB Output is correct
33 Correct 16 ms 2048 KB Output is correct
34 Correct 18 ms 2048 KB Output is correct
35 Correct 12 ms 1792 KB Output is correct
36 Correct 1 ms 1152 KB Output is correct
37 Correct 12 ms 1792 KB Output is correct
38 Correct 14 ms 2048 KB Output is correct
39 Correct 31 ms 2936 KB Output is correct
40 Correct 32 ms 2944 KB Output is correct
41 Correct 58 ms 4624 KB Output is correct
42 Correct 47 ms 3832 KB Output is correct
43 Correct 24 ms 2552 KB Output is correct
44 Correct 41 ms 3832 KB Output is correct
45 Correct 45 ms 4472 KB Output is correct
46 Correct 25 ms 2944 KB Output is correct
47 Correct 33 ms 2936 KB Output is correct
48 Correct 33 ms 2944 KB Output is correct
49 Correct 67 ms 4600 KB Output is correct
50 Correct 47 ms 3832 KB Output is correct
51 Correct 37 ms 3200 KB Output is correct
52 Correct 47 ms 3964 KB Output is correct
53 Correct 46 ms 3960 KB Output is correct
54 Correct 47 ms 4600 KB Output is correct
55 Correct 56 ms 4600 KB Output is correct