Submission #953946

# Submission time Handle Problem Language Result Execution time Memory
953946 2024-03-27T00:36:27 Z AlphaMale06 Global Warming (CEOI18_glo) C++17
62 / 100
43 ms 7260 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define int long long
#define F first
#define S second

const int inf = 1e14;
const int N = 2e5+3;
int dp[N], ndp[N];
pair<int, int> mdp[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    int a[n];
    for(int i=0; i< n; i++)cin >> a[i];
    dp[0] = inf;
    int mx=0;
    for(int i = n-1; i>=0; i--){
        if(a[i]<dp[mx]){
            mx++;
            dp[mx]=a[i];
        }
        else{
            int l = 1, r = mx;
            while(l<=r){
                int s = l+r>>1;
                if(dp[s]>=a[i])l=s+1;
                else r=s-1;
            }
            if(dp[l-1]!=a[i])dp[l]=max(dp[l], a[i]);
        }
        mdp[i] = {mx, dp[mx]};
    }
    int ans=mx;
    for(int i = 1; i<=n; i++)ndp[i]=inf+i;
    ndp[0]=-inf;
    int mxx=0;
    for(int i=0; i < n; i++){
        int l = 0, r = n;
        if(a[i]-d>ndp[mxx]){
            mxx++;
            ndp[mxx]=a[i]-d;
        }
        else{
            while(l<=r){
                int s = l+r>>1;
                if(ndp[s]>=a[i]-d)r=s-1;
                else l=s+1;
            }
            ndp[l]=min(ndp[l], a[i]-d);
        }
        l = 0, r = n;
        while(l<=r){
            int s = l+r>>1;
            if(ndp[s]<mdp[i+1].S)l=s+1;
            else r=s-1;
        }
        ans=max(ans, mdp[i+1].F+r);
    }
    cout << ans;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:33:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |                 int s = l+r>>1;
      |                         ~^~
glo.cpp:53:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |                 int s = l+r>>1;
      |                         ~^~
glo.cpp:61:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |             int s = l+r>>1;
      |                     ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Incorrect 1 ms 2396 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 6492 KB Output is correct
2 Correct 41 ms 6648 KB Output is correct
3 Correct 40 ms 6480 KB Output is correct
4 Correct 39 ms 6744 KB Output is correct
5 Correct 23 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4952 KB Output is correct
2 Correct 10 ms 5208 KB Output is correct
3 Correct 10 ms 5032 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 7 ms 5212 KB Output is correct
7 Correct 9 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5468 KB Output is correct
2 Correct 20 ms 5468 KB Output is correct
3 Correct 42 ms 6480 KB Output is correct
4 Correct 26 ms 7260 KB Output is correct
5 Correct 14 ms 5720 KB Output is correct
6 Correct 19 ms 7260 KB Output is correct
7 Correct 23 ms 7260 KB Output is correct
8 Correct 16 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Incorrect 1 ms 2396 KB Output isn't correct
20 Halted 0 ms 0 KB -