Submission #1096768

# Submission time Handle Problem Language Result Execution time Memory
1096768 2024-10-05T06:09:08 Z timetohighlight Global Warming (CEOI18_glo) C++14
100 / 100
214 ms 21748 KB
#include <bits/stdc++.h>

using namespace std;

const int N=(int) 2e5+9;

unordered_map <long long , long long > nen;

long long a[N],f[N],temp[N],f2[N];
long long st[4*N];
long long res,dp;
int n,x,idx,t;

void up(int id, int l, int r, int vt, long long val) {

    if (l>vt || r<vt) return;

    if (l==r ) {
        st[id]=max(val,st[id]);
        return;
    }

//    if (vt==2)
//    cout<<l<<" "<<r<<endl;
    int m=(l+r)/2;

    up(id*2,l,m,vt,val);
    up(id*2+1,m+1,r,vt,val);

    st[id]=max(st[id*2],st[id*2+1]);

}

long long get(int id, int l, int r, int u, int v) {
    if (l>v || r <u) return (int) -1e12;

    if (u<=l && r<=v) return st[id];

    int m=(l+r)/2;

    long long get1=get(id*2,l,m,u,v);
    long long get2=get(id*2+1,m+1,r,u,v);

//    if (u==2) {
//        cout<<l<<" "<<r<<endl;
//        cout<<get1<<" "<<get2<<endl;
//        cout<<endl;
//    }

    return max(get1,get2);
}

int small(int l, int r,long long x) {
    int vt=r;

    while (l<=r) {
        int m=(l+r)/2;
        if (temp[m]<=x) vt=m,r=m-1;
        else l=m+1;
    }

    return vt;
}

void solve() {
    res=idx;
    int pos=nen[a[n]];
    up(1,1,t,pos,f2[n]);


    for (int i=n-1; i>=1; i--) {
        int vt=upper_bound(temp+1,temp+1+n,a[i]-x)-temp;
        if (vt>n) continue;
        int pos=nen[temp[vt]];
        dp=get(1,1,t,pos,t);
        res=max(res,dp+f[i]);
        pos=nen[a[i]];
        up(1,1,t,pos,f2[i]);
    }

    cout<<res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

   // freopen("daydep.inp","r",stdin);
   // freopen("daydep.out","w",stdout);

    cin>>n>>x;

    for (int i=1; i<=n; i++)
        cin>>a[i];

    for (int i=1; i<=n; i++) {
        temp[idx+1]=(int) 1e12;
        int pos=lower_bound(temp+1,temp+idx+1,a[i])-temp;
        temp[pos]=a[i];
        idx=max(idx,pos);
        f[i]=pos;
    }
    
    
    for (int i=1; i<=n; i++) temp[i]=0;
    idx=0;

    for (int i=n; i>=1; i--) {
        temp[idx+1]=(int) -1e12;
        int pos=small(1,idx+1,a[i]);
        temp[pos]=a[i];
        idx=max(idx,pos);
        f2[i]=pos;
    }


    for (int i=1; i<=n; i++)
        temp[i]=a[i];

    sort(temp+1,temp+1+n);

    for (int i=1; i<=n; i++) {
        if (temp[i]!=temp[i-1]) t++;
        nen[temp[i]]=t;
    }

    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 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 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 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 202 ms 21628 KB Output is correct
2 Correct 203 ms 21684 KB Output is correct
3 Correct 214 ms 21748 KB Output is correct
4 Correct 200 ms 21564 KB Output is correct
5 Correct 88 ms 14268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 5548 KB Output is correct
2 Correct 44 ms 5736 KB Output is correct
3 Correct 42 ms 5616 KB Output is correct
4 Correct 18 ms 3764 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 19 ms 3760 KB Output is correct
7 Correct 32 ms 5688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10956 KB Output is correct
2 Correct 65 ms 11204 KB Output is correct
3 Correct 126 ms 21728 KB Output is correct
4 Correct 62 ms 14216 KB Output is correct
5 Correct 29 ms 10704 KB Output is correct
6 Correct 55 ms 20348 KB Output is correct
7 Correct 56 ms 20856 KB Output is correct
8 Correct 47 ms 10948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 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 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 202 ms 21628 KB Output is correct
28 Correct 203 ms 21684 KB Output is correct
29 Correct 214 ms 21748 KB Output is correct
30 Correct 200 ms 21564 KB Output is correct
31 Correct 88 ms 14268 KB Output is correct
32 Correct 38 ms 5548 KB Output is correct
33 Correct 44 ms 5736 KB Output is correct
34 Correct 42 ms 5616 KB Output is correct
35 Correct 18 ms 3764 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 19 ms 3760 KB Output is correct
38 Correct 32 ms 5688 KB Output is correct
39 Correct 58 ms 10956 KB Output is correct
40 Correct 65 ms 11204 KB Output is correct
41 Correct 126 ms 21728 KB Output is correct
42 Correct 62 ms 14216 KB Output is correct
43 Correct 29 ms 10704 KB Output is correct
44 Correct 55 ms 20348 KB Output is correct
45 Correct 56 ms 20856 KB Output is correct
46 Correct 47 ms 10948 KB Output is correct
47 Correct 84 ms 10956 KB Output is correct
48 Correct 82 ms 10956 KB Output is correct
49 Correct 200 ms 21628 KB Output is correct
50 Correct 77 ms 14172 KB Output is correct
51 Correct 54 ms 12500 KB Output is correct
52 Correct 103 ms 20920 KB Output is correct
53 Correct 56 ms 20836 KB Output is correct
54 Correct 66 ms 21572 KB Output is correct
55 Correct 143 ms 21624 KB Output is correct