Submission #362945

# Submission time Handle Problem Language Result Execution time Memory
362945 2021-02-04T19:25:27 Z shahriarkhan Global Warming (CEOI18_glo) C++14
100 / 100
1449 ms 63312 KB
#include<bits/stdc++.h>
using namespace std ;

int mx = 7e5 ;

unordered_map<int,int> mp ;

vector<int> V ;

struct tree
{
    vector<int> t ;

    tree(int n)
    {
        t = vector<int> (4*n + 4 , 0) ;
    }

    void update(int node , int low , int high , int ind , int val)
    {
        if(low>ind || high<ind) return ;
        if(low==high && low==ind)
        {
            t[node] = val ;
            return ;
        }
        int mid = (low+high)>>1 , left = node<<1 , right = left|1 ;
        update(left,low,mid,ind,val) , update(right,mid+1,high,ind,val) ;
        t[node] = max(t[left],t[right]) ;
    }

    void clean(int node , int low , int high)
    {
        if(low==high)
        {
            t[node] = 0 ;
            return ;
        }
        int mid = (low+high)>>1 , left = node<<1 , right = left|1 ;
        clean(left,low,mid) , clean(right,mid+1,high) ;
        t[node] = 0 ;
    }

    int query(int node , int low , int high , int l , int r)
    {
        if(l>r) return 0 ;
        if(r<low || l>high) return 0 ;
        if(l<=low && high<=r) return t[node] ;
        int mid = (low+high)>>1 , left = node<<1 , right = left|1 ;
        return max(query(left,low,mid,l,r) , query(right,mid+1,high,l,r)) ;
    }
};

int main()
{
    int n , x , ind = 0 ;
    scanf("%d%d",&n,&x) ;
    mp.reserve(4096) ;
    mp.max_load_factor(0.25) ;
    int a[n+1] , ans = 0 , dp[n+2][3] ;
    for(int i = 1 ; i <= n ; ++i)
    {
        scanf("%d",&a[i]) ;
        V.push_back(a[i]) ;
        V.push_back(a[i] + x - 1) ;
        V.push_back(a[i] - x + 1) ;
        dp[i][1] = 0 , dp[i][2] = 0 ;
    }
    sort(V.begin(),V.end()) ;
    for(int i : V)
    {
        if(mp[i]) continue ;
        mp[i] = ++ind ;
    }
    ++ind , ++ind ;
    mx = ind ;
    tree pref(mx+5) , suf(mx+5) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        dp[i][1] = pref.query(1,0,mx,1,mp[a[i] + x - 1]) ;
        pref.update(1,0,mx,mp[a[i]],pref.query(1,0,mx,1,mp[a[i]] - 1) + 1) ;
    }
    for(int i = n ; i >= 1 ; --i)
    {
        dp[i][2] = suf.query(1,0,mx,mp[a[i]-x+1],mx) ;
        suf.update(1,0,mx,mp[a[i]],suf.query(1,0,mx,mp[a[i]] + 1,mx) + 1) ;
    }
    pref.clean(1,0,mx) , suf.clean(1,0,mx) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        ans = max(ans,dp[i][2] + pref.query(1,0,mx,1,mp[a[i]] - 1) + 1) ;
        pref.update(1,0,mx,mp[a[i]],pref.query(1,0,mx,1,mp[a[i]] - 1) + 1) ;
    }
    for(int i = n ; i >= 1 ; --i)
    {
        ans = max(ans,dp[i][1] + suf.query(1,0,mx,mp[a[i]] + 1,mx) + 1) ;
        suf.update(1,0,mx,mp[a[i]],suf.query(1,0,mx,mp[a[i]] + 1,mx) + 1) ;
    }
    printf("%d\n",ans) ;
    return 0 ;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     scanf("%d%d",&n,&x) ;
      |     ~~~~~^~~~~~~~~~~~~~
glo.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |         scanf("%d",&a[i]) ;
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1265 ms 63312 KB Output is correct
2 Correct 1241 ms 63164 KB Output is correct
3 Correct 1256 ms 63164 KB Output is correct
4 Correct 1257 ms 63164 KB Output is correct
5 Correct 575 ms 34444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 15864 KB Output is correct
2 Correct 268 ms 15864 KB Output is correct
3 Correct 245 ms 15912 KB Output is correct
4 Correct 134 ms 11168 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 96 ms 4388 KB Output is correct
7 Correct 197 ms 13944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 622 ms 31632 KB Output is correct
2 Correct 649 ms 31504 KB Output is correct
3 Correct 1377 ms 63292 KB Output is correct
4 Correct 679 ms 34572 KB Output is correct
5 Correct 311 ms 31760 KB Output is correct
6 Correct 599 ms 61200 KB Output is correct
7 Correct 605 ms 61068 KB Output is correct
8 Correct 478 ms 31712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1265 ms 63312 KB Output is correct
28 Correct 1241 ms 63164 KB Output is correct
29 Correct 1256 ms 63164 KB Output is correct
30 Correct 1257 ms 63164 KB Output is correct
31 Correct 575 ms 34444 KB Output is correct
32 Correct 240 ms 15864 KB Output is correct
33 Correct 268 ms 15864 KB Output is correct
34 Correct 245 ms 15912 KB Output is correct
35 Correct 134 ms 11168 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 96 ms 4388 KB Output is correct
38 Correct 197 ms 13944 KB Output is correct
39 Correct 622 ms 31632 KB Output is correct
40 Correct 649 ms 31504 KB Output is correct
41 Correct 1377 ms 63292 KB Output is correct
42 Correct 679 ms 34572 KB Output is correct
43 Correct 311 ms 31760 KB Output is correct
44 Correct 599 ms 61200 KB Output is correct
45 Correct 605 ms 61068 KB Output is correct
46 Correct 478 ms 31712 KB Output is correct
47 Correct 595 ms 31708 KB Output is correct
48 Correct 633 ms 31640 KB Output is correct
49 Correct 1449 ms 63312 KB Output is correct
50 Correct 612 ms 34700 KB Output is correct
51 Correct 378 ms 26824 KB Output is correct
52 Correct 542 ms 28428 KB Output is correct
53 Correct 624 ms 63292 KB Output is correct
54 Correct 643 ms 63164 KB Output is correct
55 Correct 1022 ms 55120 KB Output is correct