Submission #284400

# Submission time Handle Problem Language Result Execution time Memory
284400 2020-08-27T10:53:18 Z Revo7 Global Warming (CEOI18_glo) C++14
58 / 100
1183 ms 30576 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;
const ll maxn=2e5+100;
const ll inf=1e9+10;
const ll mod=1e9+7;
const ll base=27;

int n,k,ans;
int b[maxn],a[maxn],pre[maxn],suf[maxn];
map<int,int>ha;
vector<int>st;

int qur(int i,int l,int r,int ql,int qr){
    if(ql>qr)return 0;
    if(r<ql||l>qr)return 0;
    if(l>=ql&&r<=qr)return st[i];
    return max(qur(left,l,mid,ql,qr),qur(righ,mid+1,r,ql,qr));
}

void upd(int i,int l,int r,int id,int val){
    if(r<id||l>id)return;
    if(l==r){
        st[i]=max(st[i],val);
        return;
    }
    upd(left,l,mid,id,val);
    upd(righ,mid+1,r,id,val);
    st[i]=max(st[left],st[righ]);
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ha[a[i]]=1;
        ha[a[i]-k]=1;
    }

    int cnt=0;
    for(auto &x:ha){
        x.second=cnt++;
    }

    st.assign(4*cnt+10,0);
    for(int i=0;i<n;i++){
        b[i]=ha[a[i]];
        pre[i]=1+qur(0,0,cnt-1,0,b[i]-1);
        upd(0,0,cnt-1,b[i],pre[i]);
        ans=max(ans,pre[i]);
    }
    //for(int i=0;i<n;i++)cout<<pre[i]<<' ';cout<<endl;

    st.assign(4*maxn+10,0);
    for(int i=n-1;i>=0;i--){
        suf[i]=1+qur(0,0,cnt-1,b[i]+1,cnt-1);
        upd(0,0,cnt-1,b[i],suf[i]);
        if(i){
            int cur=pre[i-1]+qur(0,0,cnt-1,ha[a[i-1]-k]+1,cnt-1);
            ans=max(ans,cur);
            //if(cur==6)cout<<i<<endl;
        }
    }

    //for(int i=0;i<n;i++)cout<<suf[i]<<' ';cout<<endl;
    cout<<ans<<endl;
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 3 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 3 ms 3456 KB Output is correct
11 Correct 2 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 3 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 3 ms 3456 KB Output is correct
11 Correct 2 ms 3456 KB Output is correct
12 Correct 3 ms 3456 KB Output is correct
13 Correct 3 ms 3456 KB Output is correct
14 Correct 3 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 3 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 3 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 3 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 3 ms 3456 KB Output is correct
11 Correct 2 ms 3456 KB Output is correct
12 Correct 3 ms 3456 KB Output is correct
13 Correct 3 ms 3456 KB Output is correct
14 Correct 3 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 3 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 3 ms 3456 KB Output is correct
19 Correct 5 ms 3584 KB Output is correct
20 Correct 5 ms 3584 KB Output is correct
21 Correct 5 ms 3584 KB Output is correct
22 Correct 4 ms 3584 KB Output is correct
23 Correct 4 ms 3584 KB Output is correct
24 Correct 4 ms 3584 KB Output is correct
25 Correct 4 ms 3584 KB Output is correct
26 Correct 4 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 959 ms 20216 KB Output is correct
2 Correct 1029 ms 20392 KB Output is correct
3 Correct 948 ms 20344 KB Output is correct
4 Correct 941 ms 20344 KB Output is correct
5 Correct 404 ms 13304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 10744 KB Output is correct
2 Correct 217 ms 10872 KB Output is correct
3 Correct 212 ms 10788 KB Output is correct
4 Correct 102 ms 7416 KB Output is correct
5 Correct 3 ms 3456 KB Output is correct
6 Correct 106 ms 7416 KB Output is correct
7 Correct 156 ms 9848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 539 ms 18168 KB Output is correct
2 Correct 525 ms 18124 KB Output is correct
3 Incorrect 1183 ms 30576 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 3 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 3 ms 3456 KB Output is correct
11 Correct 2 ms 3456 KB Output is correct
12 Correct 3 ms 3456 KB Output is correct
13 Correct 3 ms 3456 KB Output is correct
14 Correct 3 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 3 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 3 ms 3456 KB Output is correct
19 Correct 5 ms 3584 KB Output is correct
20 Correct 5 ms 3584 KB Output is correct
21 Correct 5 ms 3584 KB Output is correct
22 Correct 4 ms 3584 KB Output is correct
23 Correct 4 ms 3584 KB Output is correct
24 Correct 4 ms 3584 KB Output is correct
25 Correct 4 ms 3584 KB Output is correct
26 Correct 4 ms 3584 KB Output is correct
27 Correct 959 ms 20216 KB Output is correct
28 Correct 1029 ms 20392 KB Output is correct
29 Correct 948 ms 20344 KB Output is correct
30 Correct 941 ms 20344 KB Output is correct
31 Correct 404 ms 13304 KB Output is correct
32 Correct 211 ms 10744 KB Output is correct
33 Correct 217 ms 10872 KB Output is correct
34 Correct 212 ms 10788 KB Output is correct
35 Correct 102 ms 7416 KB Output is correct
36 Correct 3 ms 3456 KB Output is correct
37 Correct 106 ms 7416 KB Output is correct
38 Correct 156 ms 9848 KB Output is correct
39 Correct 539 ms 18168 KB Output is correct
40 Correct 525 ms 18124 KB Output is correct
41 Incorrect 1183 ms 30576 KB Output isn't correct
42 Halted 0 ms 0 KB -