답안 #86089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
86089 2018-11-24T18:48:26 Z zubec Global Warming (CEOI18_glo) C++14
100 / 100
77 ms 37368 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 200100;
const int MAX = 1000000100;

int n, d, pref[N], a[N], mx_posl[N], suff[N];

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

    cin >> n >> d;
    pref[0] = -MAX;
    for (int i = 1; i <= n; i++){
        pref[i] = MAX;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        int l = 0, r = i;
        cin >> a[i];
        while(l < r){
            int mid = (l+r)>>1;
            if (pref[mid] < a[i])
                l = mid+1; else
                r = mid;
        }
        pref[l] = min(pref[l], a[i]);
        mx_posl[i] = l;
        ans = max(ans, l);
    }
    for (int i = 1; i <= n; i++){
        suff[i] = -MAX;
    }
    suff[n+1] = MAX;
    for (int i = n; i >= 1; i--){
        int l = i, r = n+1;
        while(l < r){
            int mid = (l+r+1)>>1;
            if (suff[mid] > a[i]-d)
                r = mid-1; else
                l = mid;
        }
        ans = max(ans, mx_posl[i]+n-l);
        //cout << i << ' ' << l << ' ' << mx_posl[i]+n-l << ' ';
        l = i, r = n+1;
        while(l < r){
            int mid = (l+r+1)>>1;
            if (suff[mid] > a[i])
                r = mid-1; else
                l = mid;
        }
        //cout <<  l << endl;
        suff[l] = max(suff[l], a[i]);
    }
    cout << ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 1 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 1 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 788 KB Output is correct
14 Correct 2 ms 788 KB Output is correct
15 Correct 2 ms 788 KB Output is correct
16 Correct 2 ms 788 KB Output is correct
17 Correct 2 ms 800 KB Output is correct
18 Correct 2 ms 804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 1 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 788 KB Output is correct
14 Correct 2 ms 788 KB Output is correct
15 Correct 2 ms 788 KB Output is correct
16 Correct 2 ms 788 KB Output is correct
17 Correct 2 ms 800 KB Output is correct
18 Correct 2 ms 804 KB Output is correct
19 Correct 2 ms 808 KB Output is correct
20 Correct 2 ms 820 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 2 ms 904 KB Output is correct
24 Correct 2 ms 928 KB Output is correct
25 Correct 2 ms 936 KB Output is correct
26 Correct 2 ms 940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 5932 KB Output is correct
2 Correct 75 ms 7860 KB Output is correct
3 Correct 74 ms 9912 KB Output is correct
4 Correct 77 ms 11836 KB Output is correct
5 Correct 41 ms 12992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 12992 KB Output is correct
2 Correct 25 ms 12992 KB Output is correct
3 Correct 19 ms 12992 KB Output is correct
4 Correct 11 ms 12992 KB Output is correct
5 Correct 2 ms 12992 KB Output is correct
6 Correct 11 ms 12992 KB Output is correct
7 Correct 16 ms 13112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 14856 KB Output is correct
2 Correct 34 ms 15720 KB Output is correct
3 Correct 66 ms 19296 KB Output is correct
4 Correct 41 ms 20548 KB Output is correct
5 Correct 20 ms 20548 KB Output is correct
6 Correct 55 ms 22012 KB Output is correct
7 Correct 50 ms 24000 KB Output is correct
8 Correct 29 ms 24000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 1 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 2 ms 788 KB Output is correct
14 Correct 2 ms 788 KB Output is correct
15 Correct 2 ms 788 KB Output is correct
16 Correct 2 ms 788 KB Output is correct
17 Correct 2 ms 800 KB Output is correct
18 Correct 2 ms 804 KB Output is correct
19 Correct 2 ms 808 KB Output is correct
20 Correct 2 ms 820 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 2 ms 904 KB Output is correct
24 Correct 2 ms 928 KB Output is correct
25 Correct 2 ms 936 KB Output is correct
26 Correct 2 ms 940 KB Output is correct
27 Correct 75 ms 5932 KB Output is correct
28 Correct 75 ms 7860 KB Output is correct
29 Correct 74 ms 9912 KB Output is correct
30 Correct 77 ms 11836 KB Output is correct
31 Correct 41 ms 12992 KB Output is correct
32 Correct 18 ms 12992 KB Output is correct
33 Correct 25 ms 12992 KB Output is correct
34 Correct 19 ms 12992 KB Output is correct
35 Correct 11 ms 12992 KB Output is correct
36 Correct 2 ms 12992 KB Output is correct
37 Correct 11 ms 12992 KB Output is correct
38 Correct 16 ms 13112 KB Output is correct
39 Correct 34 ms 14856 KB Output is correct
40 Correct 34 ms 15720 KB Output is correct
41 Correct 66 ms 19296 KB Output is correct
42 Correct 41 ms 20548 KB Output is correct
43 Correct 20 ms 20548 KB Output is correct
44 Correct 55 ms 22012 KB Output is correct
45 Correct 50 ms 24000 KB Output is correct
46 Correct 29 ms 24000 KB Output is correct
47 Correct 36 ms 24420 KB Output is correct
48 Correct 36 ms 25512 KB Output is correct
49 Correct 77 ms 28924 KB Output is correct
50 Correct 41 ms 30080 KB Output is correct
51 Correct 37 ms 30124 KB Output is correct
52 Correct 41 ms 32256 KB Output is correct
53 Correct 48 ms 33492 KB Output is correct
54 Correct 55 ms 35392 KB Output is correct
55 Correct 62 ms 37368 KB Output is correct