답안 #284401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284401 2020-08-27T10:54:34 Z Revo7 Global Warming (CEOI18_glo) C++14
58 / 100
1284 ms 44280 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;

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

ll qur(ll i,ll l,ll r,ll ql,ll 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(ll i,ll l,ll r,ll id,ll 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(ll i=0;i<n;i++){
        cin>>a[i];
        ha[a[i]]=1;
        ha[a[i]-k]=1;
    }

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

    st.assign(4*cnt+10,0);
    for(ll 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(ll i=0;i<n;i++)cout<<pre[i]<<' ';cout<<endl;

    st.assign(4*maxn+10,0);
    for(ll 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){
            ll 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(ll i=0;i<n;i++)cout<<suf[i]<<' ';cout<<endl;
    cout<<ans<<endl;
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6656 KB Output is correct
3 Correct 4 ms 6656 KB Output is correct
4 Correct 4 ms 6656 KB Output is correct
5 Correct 5 ms 6656 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 4 ms 6656 KB Output is correct
10 Correct 4 ms 6656 KB Output is correct
11 Correct 4 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6656 KB Output is correct
3 Correct 4 ms 6656 KB Output is correct
4 Correct 4 ms 6656 KB Output is correct
5 Correct 5 ms 6656 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 4 ms 6656 KB Output is correct
10 Correct 4 ms 6656 KB Output is correct
11 Correct 4 ms 6656 KB Output is correct
12 Correct 4 ms 6656 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 4 ms 6656 KB Output is correct
15 Correct 4 ms 6656 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6656 KB Output is correct
3 Correct 4 ms 6656 KB Output is correct
4 Correct 4 ms 6656 KB Output is correct
5 Correct 5 ms 6656 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 4 ms 6656 KB Output is correct
10 Correct 4 ms 6656 KB Output is correct
11 Correct 4 ms 6656 KB Output is correct
12 Correct 4 ms 6656 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 4 ms 6656 KB Output is correct
15 Correct 4 ms 6656 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6656 KB Output is correct
19 Correct 7 ms 6784 KB Output is correct
20 Correct 6 ms 6784 KB Output is correct
21 Correct 7 ms 6784 KB Output is correct
22 Correct 6 ms 6784 KB Output is correct
23 Correct 6 ms 6784 KB Output is correct
24 Correct 6 ms 6784 KB Output is correct
25 Correct 6 ms 6784 KB Output is correct
26 Correct 6 ms 6784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1032 ms 30072 KB Output is correct
2 Correct 1080 ms 30160 KB Output is correct
3 Correct 1098 ms 30072 KB Output is correct
4 Correct 1089 ms 30072 KB Output is correct
5 Correct 404 ms 20728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 17144 KB Output is correct
2 Correct 234 ms 17144 KB Output is correct
3 Correct 227 ms 17272 KB Output is correct
4 Correct 123 ms 12496 KB Output is correct
5 Correct 5 ms 6656 KB Output is correct
6 Correct 110 ms 12536 KB Output is correct
7 Correct 171 ms 15736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 27768 KB Output is correct
2 Correct 574 ms 27768 KB Output is correct
3 Incorrect 1284 ms 44280 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 4 ms 6656 KB Output is correct
3 Correct 4 ms 6656 KB Output is correct
4 Correct 4 ms 6656 KB Output is correct
5 Correct 5 ms 6656 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 4 ms 6656 KB Output is correct
10 Correct 4 ms 6656 KB Output is correct
11 Correct 4 ms 6656 KB Output is correct
12 Correct 4 ms 6656 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 4 ms 6656 KB Output is correct
15 Correct 4 ms 6656 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6656 KB Output is correct
19 Correct 7 ms 6784 KB Output is correct
20 Correct 6 ms 6784 KB Output is correct
21 Correct 7 ms 6784 KB Output is correct
22 Correct 6 ms 6784 KB Output is correct
23 Correct 6 ms 6784 KB Output is correct
24 Correct 6 ms 6784 KB Output is correct
25 Correct 6 ms 6784 KB Output is correct
26 Correct 6 ms 6784 KB Output is correct
27 Correct 1032 ms 30072 KB Output is correct
28 Correct 1080 ms 30160 KB Output is correct
29 Correct 1098 ms 30072 KB Output is correct
30 Correct 1089 ms 30072 KB Output is correct
31 Correct 404 ms 20728 KB Output is correct
32 Correct 232 ms 17144 KB Output is correct
33 Correct 234 ms 17144 KB Output is correct
34 Correct 227 ms 17272 KB Output is correct
35 Correct 123 ms 12496 KB Output is correct
36 Correct 5 ms 6656 KB Output is correct
37 Correct 110 ms 12536 KB Output is correct
38 Correct 171 ms 15736 KB Output is correct
39 Correct 572 ms 27768 KB Output is correct
40 Correct 574 ms 27768 KB Output is correct
41 Incorrect 1284 ms 44280 KB Output isn't correct
42 Halted 0 ms 0 KB -