Submission #422509

# Submission time Handle Problem Language Result Execution time Memory
422509 2021-06-10T07:46:05 Z Emin2004 Global Warming (CEOI18_glo) C++14
100 / 100
133 ms 14696 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pii pair <ll, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846

const int N = 200005;
const int mod = 1e9 + 7;

ll lis[N], lds[N], a[N];
ll mp[N];

int main() {
    io;
    ll n, d;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mp[i + 1] = INT_MAX;
    }
    ll ans = 0;
    mp[1] = a[0];
    lis[0] = 1;
    for(int i = 1; i < n; i++){
        ll l = 1, r = n;
        lis[i] = 1;
        while(l <= r){
            ll mid = (l + r) / 2;
            if(mp[mid] < a[i]){
                mp[mid + 1] = min(mp[mid + 1], a[i]);
                lis[i] = max(lis[i], mid + 1);
                l = mid + 1;
                ans = max(ans, l);
            }
            else{
                r = mid - 1;
            }
        }
        mp[1] = min(mp[1], a[i]);
    }
    if(d == 0){
        cout << ans;
        return 0;
    }
    for(int i = 1; i <= n; i++){
        mp[i] = 0;
    }
    mp[1] = a[n - 1];
    lds[n - 1] = 1;
    for(int i = n - 2; i >= 0; i--){
        ll l = 1, r = n;
        lds[i] = 1;
        while(l <= r){
            ll mid = (l + r) / 2;
            if(mp[mid] > a[i]){
                mp[mid + 1] = max(mp[mid + 1], a[i]);
                lds[i] = max(lds[i], mid + 1);
                l = mid + 1;
            }
            else{
                r = mid - 1;
            }
        }
        mp[1] = max(mp[1], a[i]);
    }
    for(int i = 1; i <= n; i++){
        mp[i] = -1;
    }
    set<pii> s;
    s.insert({a[0], 1});
    mp[1] = a[0];
    for(int i = 1; i < n; i++){
        ll cur = lds[i];
        ll k = a[i] + d;
        set<pii>::iterator itr = s.lower_bound({k, 0});
       // cout << (*itr).F << " " << " " << lis[i] << " ";
        if(itr != s.begin()) itr--;
        else cur = INT_MIN;
        cur += (*itr).S;
        if(mp[lis[i]] > a[i]){
            s.erase(s.find({mp[lis[i]], lis[i]}));
            s.insert({a[i], lis[i]});
            mp[lis[i]] = a[i];
        }
        if(mp[lis[i]] == -1){
            s.insert({a[i], lis[i]});
            mp[lis[i]] = a[i];
        }
        //if(i == 4) cout << cur << " " ;
        ans = max(ans, cur);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 6820 KB Output is correct
2 Correct 42 ms 6872 KB Output is correct
3 Correct 49 ms 6912 KB Output is correct
4 Correct 42 ms 6920 KB Output is correct
5 Correct 32 ms 6084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2380 KB Output is correct
2 Correct 28 ms 2352 KB Output is correct
3 Correct 27 ms 2380 KB Output is correct
4 Correct 24 ms 3724 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 27 ms 3652 KB Output is correct
7 Correct 22 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 4444 KB Output is correct
2 Correct 49 ms 4392 KB Output is correct
3 Correct 102 ms 8512 KB Output is correct
4 Correct 91 ms 13976 KB Output is correct
5 Correct 57 ms 7084 KB Output is correct
6 Correct 99 ms 13400 KB Output is correct
7 Correct 84 ms 14020 KB Output is correct
8 Correct 42 ms 4376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 42 ms 6820 KB Output is correct
28 Correct 42 ms 6872 KB Output is correct
29 Correct 49 ms 6912 KB Output is correct
30 Correct 42 ms 6920 KB Output is correct
31 Correct 32 ms 6084 KB Output is correct
32 Correct 27 ms 2380 KB Output is correct
33 Correct 28 ms 2352 KB Output is correct
34 Correct 27 ms 2380 KB Output is correct
35 Correct 24 ms 3724 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 27 ms 3652 KB Output is correct
38 Correct 22 ms 2284 KB Output is correct
39 Correct 49 ms 4444 KB Output is correct
40 Correct 49 ms 4392 KB Output is correct
41 Correct 102 ms 8512 KB Output is correct
42 Correct 91 ms 13976 KB Output is correct
43 Correct 57 ms 7084 KB Output is correct
44 Correct 99 ms 13400 KB Output is correct
45 Correct 84 ms 14020 KB Output is correct
46 Correct 42 ms 4376 KB Output is correct
47 Correct 56 ms 4436 KB Output is correct
48 Correct 65 ms 4448 KB Output is correct
49 Correct 116 ms 8536 KB Output is correct
50 Correct 87 ms 13920 KB Output is correct
51 Correct 76 ms 12096 KB Output is correct
52 Correct 133 ms 14020 KB Output is correct
53 Correct 108 ms 14020 KB Output is correct
54 Correct 86 ms 14696 KB Output is correct
55 Correct 94 ms 8788 KB Output is correct