Submission #952955

# Submission time Handle Problem Language Result Execution time Memory
952955 2024-03-25T07:25:26 Z irmuun Global Warming (CEOI18_glo) C++17
100 / 100
118 ms 17364 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

struct segtree{
    ll n;
    vector<ll>d;
    segtree(ll n):n(n){
        d.resize(4*n);
        build(1,1,n);
    }
    void build(ll node,ll l,ll r){
        if(l==r){
            d[node]=0;
            return;
        }
        ll mid=(l+r)/2;
        build(node*2,l,mid);
        build(node*2+1,mid+1,r);
        d[node]=0;
    }
    ll query(ll node,ll l,ll r,ll L,ll R){
        if(R<L||r<L||R<l) return 0ll;
        if(L<=l&&r<=R){
            return d[node];
        }
        ll mid=(l+r)/2;
        return max(query(node*2,l,mid,L,R),query(node*2+1,mid+1,r,L,R));
   }
    void update(ll node,ll l,ll r,ll pos,ll val){
        if(pos<l||r<pos) return;
        if(l==r){
            d[node]=val;
            return;
        }
        ll mid=(l+r)/2;
        update(node*2,l,mid,pos,val);
        update(node*2+1,mid+1,r,pos,val);
        d[node]=max(d[node*2],d[node*2+1]);
    }
};

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,x;
    cin>>n>>x;
    ll t[n+5];
    for(ll i=1;i<=n;i++){
        cin>>t[i];
    }
    ll pre[n+5],ans=0;
    vector<ll>v;
    for(ll i=1;i<=n;i++){
        if(v.empty()||v.back()<t[i]){
            v.pb(t[i]);
            pre[i]=v.size();
        }
        else{
            ll x=lower_bound(all(v),t[i])-v.begin();
            v[x]=t[i];
            pre[i]=x+1;
        }
    }
    ans=v.size();
    v.clear();
    ll suf[n+5];
    suf[n+1]=0;
    for(ll i=n;i>=1;i--){
        if(v.empty()||v.back()<-t[i]){
            v.pb(-t[i]);
            suf[i]=v.size();
        }
        else{
            ll x=lower_bound(all(v),-t[i])-v.begin();
            v[x]=-t[i];
            suf[i]=x+1;
        }
    }
    segtree sg(n);
    pair<ll,ll>p[n+5];
    for(ll i=1;i<=n;i++){
        p[i].ff=t[i];
        p[i].ss=i;
    }
    sort(p+1,p+n+1);
    p[n+1].ss=0;
    ll l=n+1;
    for(ll i=n;i>=1;i--){
        while(l>1&&p[l-1].ff>p[i].ff-x){
            l--;
            sg.update(1,1,n,p[l].ss,suf[p[l].ss]);
        }
        ans=max(ans,pre[p[i].ss]+sg.query(1,1,n,p[i].ss+1,n));
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 16468 KB Output is correct
2 Correct 110 ms 16464 KB Output is correct
3 Correct 114 ms 16464 KB Output is correct
4 Correct 110 ms 16464 KB Output is correct
5 Correct 67 ms 16592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 4556 KB Output is correct
2 Correct 28 ms 4444 KB Output is correct
3 Correct 25 ms 4444 KB Output is correct
4 Correct 17 ms 4576 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 15 ms 4576 KB Output is correct
7 Correct 21 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 8272 KB Output is correct
2 Correct 54 ms 8284 KB Output is correct
3 Correct 111 ms 16464 KB Output is correct
4 Correct 69 ms 16592 KB Output is correct
5 Correct 30 ms 8412 KB Output is correct
6 Correct 56 ms 16076 KB Output is correct
7 Correct 57 ms 16344 KB Output is correct
8 Correct 43 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 110 ms 16468 KB Output is correct
28 Correct 110 ms 16464 KB Output is correct
29 Correct 114 ms 16464 KB Output is correct
30 Correct 110 ms 16464 KB Output is correct
31 Correct 67 ms 16592 KB Output is correct
32 Correct 25 ms 4556 KB Output is correct
33 Correct 28 ms 4444 KB Output is correct
34 Correct 25 ms 4444 KB Output is correct
35 Correct 17 ms 4576 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 15 ms 4576 KB Output is correct
38 Correct 21 ms 4444 KB Output is correct
39 Correct 53 ms 8272 KB Output is correct
40 Correct 54 ms 8284 KB Output is correct
41 Correct 111 ms 16464 KB Output is correct
42 Correct 69 ms 16592 KB Output is correct
43 Correct 30 ms 8412 KB Output is correct
44 Correct 56 ms 16076 KB Output is correct
45 Correct 57 ms 16344 KB Output is correct
46 Correct 43 ms 8272 KB Output is correct
47 Correct 55 ms 8280 KB Output is correct
48 Correct 52 ms 8676 KB Output is correct
49 Correct 118 ms 16500 KB Output is correct
50 Correct 71 ms 16612 KB Output is correct
51 Correct 52 ms 12756 KB Output is correct
52 Correct 65 ms 16584 KB Output is correct
53 Correct 57 ms 16600 KB Output is correct
54 Correct 59 ms 17364 KB Output is correct
55 Correct 93 ms 16464 KB Output is correct