답안 #140565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140565 2019-08-03T14:36:53 Z HellAngel Global Warming (CEOI18_glo) C++14
100 / 100
71 ms 9336 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int maxn = 2e5 + 7;

int n, x, a[maxn], d[maxn], Max = 0, prf[maxn], suf[maxn], ans, Maxa = 0, b[maxn];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    cin >> n >> x;
    for(int i = 1; i <= n; i++) cin >> a[i], Maxa = max(Maxa, a[i]);
    for(int i = 1; i <= n; i++) b[i] = Maxa - a[i] + 1;
    Max = 0;
    d[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        int l = 0;
        int r = Max;
        while(l <= r)
        {
            int mid = l + r >> 1;
            if(a[i] > d[mid]) l = mid + 1;
            else r = mid - 1;
        }
        Max = max(Max, l);
        d[l] = a[i];
        prf[i] = l;
    }
    Max = 0;
    d[0] = 0;
    for(int i = n; i >= 1; i--)
    {
        int l = 0;
        int r = Max;
        while(l <= r)
        {
            int mid = l + r >> 1;
            if(b[i] > d[mid]) l = mid + 1;
            else r = mid - 1;
        }
        Max = max(Max, l);
        d[l] = b[i];
        suf[i] = l;
    }
    ans = Max;
    Max = 0;
    d[0] = LLONG_MIN;
    for(int i = 1; i < n; i++)
    {
        d[prf[i]] = a[i] - x;
        Max = max(Max, prf[i]);
        int l = 0;
        int r = Max;
        while(l <= r)
        {
            int mid = l + r >> 1;
            if(d[mid] < a[i + 1]) l = mid + 1;
            else r = mid - 1;
        }
        ans = max(ans, suf[i + 1] + r);
    }
    cout << ans;
}

Compilation message

glo.cpp: In function 'int32_t main()':
glo.cpp:26:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int mid = l + r >> 1;
                       ~~^~~
glo.cpp:42:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int mid = l + r >> 1;
                       ~~^~~
glo.cpp:61:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int mid = l + r >> 1;
                       ~~^~~
glo.cpp:14:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:14:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 6552 KB Output is correct
2 Correct 70 ms 6616 KB Output is correct
3 Correct 71 ms 6648 KB Output is correct
4 Correct 69 ms 6648 KB Output is correct
5 Correct 42 ms 7428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1912 KB Output is correct
2 Correct 19 ms 1912 KB Output is correct
3 Correct 21 ms 1912 KB Output is correct
4 Correct 13 ms 2168 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 11 ms 2424 KB Output is correct
7 Correct 16 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3448 KB Output is correct
2 Correct 31 ms 4472 KB Output is correct
3 Correct 61 ms 8568 KB Output is correct
4 Correct 41 ms 8568 KB Output is correct
5 Correct 21 ms 4472 KB Output is correct
6 Correct 38 ms 8312 KB Output is correct
7 Correct 42 ms 8952 KB Output is correct
8 Correct 27 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 70 ms 6552 KB Output is correct
28 Correct 70 ms 6616 KB Output is correct
29 Correct 71 ms 6648 KB Output is correct
30 Correct 69 ms 6648 KB Output is correct
31 Correct 42 ms 7428 KB Output is correct
32 Correct 18 ms 1912 KB Output is correct
33 Correct 19 ms 1912 KB Output is correct
34 Correct 21 ms 1912 KB Output is correct
35 Correct 13 ms 2168 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 11 ms 2424 KB Output is correct
38 Correct 16 ms 2424 KB Output is correct
39 Correct 30 ms 3448 KB Output is correct
40 Correct 31 ms 4472 KB Output is correct
41 Correct 61 ms 8568 KB Output is correct
42 Correct 41 ms 8568 KB Output is correct
43 Correct 21 ms 4472 KB Output is correct
44 Correct 38 ms 8312 KB Output is correct
45 Correct 42 ms 8952 KB Output is correct
46 Correct 27 ms 4472 KB Output is correct
47 Correct 35 ms 4472 KB Output is correct
48 Correct 36 ms 4444 KB Output is correct
49 Correct 71 ms 8568 KB Output is correct
50 Correct 42 ms 8568 KB Output is correct
51 Correct 34 ms 6648 KB Output is correct
52 Correct 41 ms 8696 KB Output is correct
53 Correct 40 ms 8696 KB Output is correct
54 Correct 45 ms 9336 KB Output is correct
55 Correct 59 ms 8568 KB Output is correct