답안 #73125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73125 2018-08-27T18:06:31 Z win11905 Global Warming (CEOI18_glo) C++11
100 / 100
260 ms 7016 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define x first
#define y second

const int N = 2e5+5;

int n, x, A[N], pos[N];
int ret[N], t[N<<1];

void update(int x, int v) {
    for(t[x+=n] = v; x != 1; x >>= 1) t[x>>1] = max(t[x], t[x^1]);
}

int query(int r) {
    int l = 0, mx = 0;
    for(l += n, r += n+1; l < r; l >>= 1, r >>= 1) {
        if(l & 1) mx = max(mx, t[l++]);
        if(r & 1) mx = max(mx, t[--r]);
    }
    return mx;
}

int main() {
    scanf("%d %d", &n, &x);
    vector<int> V, Z;
    vector<pii> ret;
    for(int i = 1; i <= n; ++i) scanf("%d", A+i), Z.emplace_back(A[i]), ret.emplace_back(A[i], i);
    sort(ret.begin(), ret.end()), sort(Z.begin(), Z.end());
    for(int i = 0; i < n; ++i) pos[ret[i].y] = i;
    for(int i = 1; i <= n; ++i) {
        auto it = lower_bound(V.begin(), V.end(), A[i]);
        if(it == V.end()) V.emplace_back(A[i]), it = V.end(), it--;
        else *it = A[i];
        update(pos[i], it - V.begin() + 1);
    }
    V.clear();
    int mx = 0;
    for(int i = n; i; --i) {
        update(pos[i], 0);
        auto it = lower_bound(V.begin(), V.end(), -A[i]);
        if(it == V.end()) V.emplace_back(-A[i]), it = V.end(), it--;
        else *it = -A[i];
        int z = it - V.begin() + 1; 
        mx = max(mx, z + query(lower_bound(Z.begin(), Z.end(), A[i]+x) - Z.begin()-1));
    }
    printf("%d\n", mx);
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &x);
     ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:30:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; ++i) scanf("%d", A+i), Z.emplace_back(A[i]), ret.emplace_back(A[i], i);
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 3 ms 528 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 3 ms 528 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 3 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 700 KB Output is correct
15 Correct 2 ms 712 KB Output is correct
16 Correct 3 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 3 ms 528 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 3 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 700 KB Output is correct
15 Correct 2 ms 712 KB Output is correct
16 Correct 3 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 712 KB Output is correct
20 Correct 3 ms 712 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 3 ms 712 KB Output is correct
23 Correct 4 ms 712 KB Output is correct
24 Correct 3 ms 712 KB Output is correct
25 Correct 3 ms 712 KB Output is correct
26 Correct 4 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 6208 KB Output is correct
2 Correct 215 ms 6208 KB Output is correct
3 Correct 222 ms 6208 KB Output is correct
4 Correct 260 ms 6336 KB Output is correct
5 Correct 107 ms 6996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 6996 KB Output is correct
2 Correct 45 ms 6996 KB Output is correct
3 Correct 45 ms 6996 KB Output is correct
4 Correct 35 ms 6996 KB Output is correct
5 Correct 3 ms 6996 KB Output is correct
6 Correct 28 ms 6996 KB Output is correct
7 Correct 58 ms 6996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 6996 KB Output is correct
2 Correct 70 ms 6996 KB Output is correct
3 Correct 176 ms 6996 KB Output is correct
4 Correct 106 ms 6996 KB Output is correct
5 Correct 45 ms 6996 KB Output is correct
6 Correct 68 ms 6996 KB Output is correct
7 Correct 72 ms 6996 KB Output is correct
8 Correct 67 ms 6996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 3 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 3 ms 528 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 3 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 700 KB Output is correct
15 Correct 2 ms 712 KB Output is correct
16 Correct 3 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 712 KB Output is correct
20 Correct 3 ms 712 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 3 ms 712 KB Output is correct
23 Correct 4 ms 712 KB Output is correct
24 Correct 3 ms 712 KB Output is correct
25 Correct 3 ms 712 KB Output is correct
26 Correct 4 ms 712 KB Output is correct
27 Correct 198 ms 6208 KB Output is correct
28 Correct 215 ms 6208 KB Output is correct
29 Correct 222 ms 6208 KB Output is correct
30 Correct 260 ms 6336 KB Output is correct
31 Correct 107 ms 6996 KB Output is correct
32 Correct 43 ms 6996 KB Output is correct
33 Correct 45 ms 6996 KB Output is correct
34 Correct 45 ms 6996 KB Output is correct
35 Correct 35 ms 6996 KB Output is correct
36 Correct 3 ms 6996 KB Output is correct
37 Correct 28 ms 6996 KB Output is correct
38 Correct 58 ms 6996 KB Output is correct
39 Correct 68 ms 6996 KB Output is correct
40 Correct 70 ms 6996 KB Output is correct
41 Correct 176 ms 6996 KB Output is correct
42 Correct 106 ms 6996 KB Output is correct
43 Correct 45 ms 6996 KB Output is correct
44 Correct 68 ms 6996 KB Output is correct
45 Correct 72 ms 6996 KB Output is correct
46 Correct 67 ms 6996 KB Output is correct
47 Correct 90 ms 6996 KB Output is correct
48 Correct 96 ms 6996 KB Output is correct
49 Correct 196 ms 6996 KB Output is correct
50 Correct 104 ms 7016 KB Output is correct
51 Correct 118 ms 7016 KB Output is correct
52 Correct 120 ms 7016 KB Output is correct
53 Correct 85 ms 7016 KB Output is correct
54 Correct 78 ms 7016 KB Output is correct
55 Correct 149 ms 7016 KB Output is correct