답안 #506093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
506093 2022-01-11T15:15:57 Z MasterTaster Global Warming (CEOI18_glo) C++14
100 / 100
73 ms 4972 KB
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 200010
#define endl "\n"

using namespace std;

int n, x, a[MAXN], b[MAXN], dp[MAXN], lvd[MAXN], ress=-1; ///lvd=lis veci desno

int binarna(int cnt, int k)
{
    int l=0, r=cnt-1;
    int ret=-1;
    while (l<=r)
    {
        int mid=l+(r-l)/2;
        if (dp[mid]<k)
        {
            ret=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return ret;
}
int prviveci(int cnt, int k)
{
    int l=0, r=cnt-1;
    int ret=-1;
    while (l<=r)
    {
        int mid=l+(r-l)/2;
        if (dp[mid]>k)
        {
            ret=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>>n>>x;
    int maxx=-1;
    for (int i=0; i<n; i++) { cin>>a[i]; maxx=max(maxx, a[i]); }

    for (int i=0; i<n; i++) b[i]=maxx-a[i];

    dp[0]=b[n-1];
    int cnt=1;
    lvd[n-1]=0; lvd[n-2]=0;
    if (a[n-1]>(a[n-2]-x)) lvd[n-2]=1;
    for (int i=n-2; i>/*=*/0; i--)
    {
        if (b[i]<dp[0]) dp[0]=b[i];
        else if (b[i]>dp[cnt-1]) dp[cnt++]=b[i];
        else
        {
            auto gde=prviveci(cnt, b[i]);
            if (gde==0 || dp[gde-1]!=b[i])
            {
                auto gde=prviveci(cnt, b[i]);
                dp[gde]=b[i];
            }
        }
        int kolko=a[i-1]-x;
        //cout<<i-1<<" "<<maxx-kolko<<" "<<cnt<<endl;
        lvd[i-1]=binarna(cnt, maxx-kolko)+1;
    }

    //for (int i=0; i<n; i++) cout<<lvd[i]<<" ";
    //cout<<endl;

    a[0]-=x;
    dp[0]=a[0];
    ress=max(ress, lvd[0]+1);
    cnt=1;
    for (int i=1; i<n; i++)
    {
        a[i]-=x;
        if (a[i]<dp[0]) dp[0]=a[i];
        else if (a[i]>dp[cnt-1]) dp[cnt++]=a[i];
        else
        {
            auto gde=prviveci(cnt, a[i]);
            if (gde==0 || dp[gde-1]!=a[i])
            {
                auto gde=prviveci(cnt, a[i]);
                dp[gde]=a[i];
            }
        }
        int kolko=binarna(cnt, a[i]);
        kolko++;
        ress=max(ress, (kolko+lvd[i]+1));
    }
    ress=max(ress, cnt);
    cout<<ress;

}
/*
15
20
1 7 3 20 8 3 17 10 3 27 14 17 13 9 15

5
10
1 4 2 7 10

5
1
1 4 2 7 10
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 3268 KB Output is correct
2 Correct 73 ms 3296 KB Output is correct
3 Correct 60 ms 3176 KB Output is correct
4 Correct 56 ms 3224 KB Output is correct
5 Correct 33 ms 3612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1344 KB Output is correct
2 Correct 13 ms 1356 KB Output is correct
3 Correct 12 ms 1340 KB Output is correct
4 Correct 7 ms 1208 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 7 ms 1228 KB Output is correct
7 Correct 11 ms 1348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2116 KB Output is correct
2 Correct 26 ms 2124 KB Output is correct
3 Correct 52 ms 3288 KB Output is correct
4 Correct 31 ms 3564 KB Output is correct
5 Correct 13 ms 2188 KB Output is correct
6 Correct 21 ms 3472 KB Output is correct
7 Correct 26 ms 3504 KB Output is correct
8 Correct 20 ms 2188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 57 ms 3268 KB Output is correct
28 Correct 73 ms 3296 KB Output is correct
29 Correct 60 ms 3176 KB Output is correct
30 Correct 56 ms 3224 KB Output is correct
31 Correct 33 ms 3612 KB Output is correct
32 Correct 13 ms 1344 KB Output is correct
33 Correct 13 ms 1356 KB Output is correct
34 Correct 12 ms 1340 KB Output is correct
35 Correct 7 ms 1208 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 7 ms 1228 KB Output is correct
38 Correct 11 ms 1348 KB Output is correct
39 Correct 25 ms 2116 KB Output is correct
40 Correct 26 ms 2124 KB Output is correct
41 Correct 52 ms 3288 KB Output is correct
42 Correct 31 ms 3564 KB Output is correct
43 Correct 13 ms 2188 KB Output is correct
44 Correct 21 ms 3472 KB Output is correct
45 Correct 26 ms 3504 KB Output is correct
46 Correct 20 ms 2188 KB Output is correct
47 Correct 27 ms 1988 KB Output is correct
48 Correct 29 ms 2088 KB Output is correct
49 Correct 59 ms 3140 KB Output is correct
50 Correct 29 ms 3568 KB Output is correct
51 Correct 25 ms 2976 KB Output is correct
52 Correct 30 ms 3524 KB Output is correct
53 Correct 24 ms 4280 KB Output is correct
54 Correct 26 ms 4972 KB Output is correct
55 Correct 45 ms 4608 KB Output is correct