Submission #1008137

# Submission time Handle Problem Language Result Execution time Memory
1008137 2024-06-26T07:55:42 Z vjudge1 Global Warming (CEOI18_glo) C++17
100 / 100
305 ms 24428 KB
#include <bits/stdc++.h>

#define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
const ll N=exp2(ceil(log2(1e6)));
ll n,x;
ll arr[1000001];
ll arr1[1000001];
ll tre[N*4][2];
ll que(ll l,ll r,ll i,ll lq,ll rq,ll type){
    if(l>rq||r<lq) return 0;
    if(r<=rq&&l>=lq) return tre[i][type];
    ll mid=(l+r)/2;
    return max(que(l,mid,i*2,lq,rq,type),que(mid+1,r,i*2+1,lq,rq,type));
}
void upd(ll idx,ll val,ll type){
    idx+=N;
    tre[idx][type]=max(tre[idx][type],val);
    idx/=2;
    while(idx){
        tre[idx][type]=max(tre[idx*2][type],tre[idx*2+1][type]);
        idx/=2;
    }
}
ll cnt=1;
void solve(){
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        arr1[cnt]=arr[i];
        cnt++;
        arr1[cnt]=arr[i]+x;
        cnt++;
    }
    sort(arr1+1,arr1+cnt);
    for(int i=0;i<n;i++){
        ll idx=lower_bound(arr1+1,arr1+cnt,arr[i])-arr1-1;
        ll last=lower_bound(arr1+1,arr1+cnt,arr[i]+x)-arr1-1;
        ll val=que(0,N-1,1,0,idx,0)+1;
        ll val1=que(0,N-1,1,1,last,0)+1;
        ll val2=que(0,N-1,1,1,idx,1)+1;
        upd(idx+1,val,0);
        upd(idx+1,val1,1);
        upd(idx+1,val2,1);
    }
    co max(tre[1][0],tre[1][1]);
}

int main()
{
    suiii
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 1 ms 10724 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 1 ms 10724 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 1 ms 10724 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 2 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 2 ms 4696 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 2 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 283 ms 23892 KB Output is correct
2 Correct 292 ms 23904 KB Output is correct
3 Correct 278 ms 20924 KB Output is correct
4 Correct 275 ms 22100 KB Output is correct
5 Correct 189 ms 16968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 9792 KB Output is correct
2 Correct 53 ms 9560 KB Output is correct
3 Correct 52 ms 8344 KB Output is correct
4 Correct 39 ms 9972 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 43 ms 11352 KB Output is correct
7 Correct 54 ms 9796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 9800 KB Output is correct
2 Correct 123 ms 11612 KB Output is correct
3 Correct 280 ms 17696 KB Output is correct
4 Correct 173 ms 12856 KB Output is correct
5 Correct 100 ms 11600 KB Output is correct
6 Correct 165 ms 18716 KB Output is correct
7 Correct 162 ms 18772 KB Output is correct
8 Correct 114 ms 13088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 1 ms 10724 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10588 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 2 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 2 ms 4696 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 2 ms 4696 KB Output is correct
27 Correct 283 ms 23892 KB Output is correct
28 Correct 292 ms 23904 KB Output is correct
29 Correct 278 ms 20924 KB Output is correct
30 Correct 275 ms 22100 KB Output is correct
31 Correct 189 ms 16968 KB Output is correct
32 Correct 69 ms 9792 KB Output is correct
33 Correct 53 ms 9560 KB Output is correct
34 Correct 52 ms 8344 KB Output is correct
35 Correct 39 ms 9972 KB Output is correct
36 Correct 1 ms 6488 KB Output is correct
37 Correct 43 ms 11352 KB Output is correct
38 Correct 54 ms 9796 KB Output is correct
39 Correct 127 ms 9800 KB Output is correct
40 Correct 123 ms 11612 KB Output is correct
41 Correct 280 ms 17696 KB Output is correct
42 Correct 173 ms 12856 KB Output is correct
43 Correct 100 ms 11600 KB Output is correct
44 Correct 165 ms 18716 KB Output is correct
45 Correct 162 ms 18772 KB Output is correct
46 Correct 114 ms 13088 KB Output is correct
47 Correct 136 ms 14932 KB Output is correct
48 Correct 129 ms 14940 KB Output is correct
49 Correct 305 ms 24428 KB Output is correct
50 Correct 183 ms 18396 KB Output is correct
51 Correct 127 ms 18384 KB Output is correct
52 Correct 195 ms 24400 KB Output is correct
53 Correct 161 ms 19012 KB Output is correct
54 Correct 199 ms 19028 KB Output is correct
55 Correct 224 ms 23892 KB Output is correct