답안 #532270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532270 2022-03-02T16:04:10 Z HaYoungJoon Global Warming (CEOI18_glo) C++14
100 / 100
204 ms 9536 KB
#include <bits/stdc++.h>
#define INF 1e9 + 7

using namespace std;

typedef pair<int,int> pii;
int n, X, a[200001], res1[200001], res2[200001], L[200001];
map<int,int> mp;
int t[600001], posinIT[200001];

void update(int v, int tl, int tr, int pos, int val) {
    if (tl == tr) {
        t[v] = val;
        return;
    }
    int tm = (tl + tr)/2;
    if (pos <= tm) update(2*v,tl,tm,pos,val);
    else update(2*v+1,tm+1,tr,pos,val);
    t[v] = max(t[2*v],t[2*v+1]);
}

int getMax(int v, int tl, int tr, int l, int r) {
    if (l > r) return -INF;
    if (tl > r || tr < l) return -INF;
    if (tl >= l && tr <= r) return t[v];
    int tm = (tl + tr)/2;
    return max(getMax(2*v,tl,tm,l,r),getMax(2*v+1,tm+1,tr,l,r));
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> X;
    vector<pii> tmp;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        tmp.push_back(pii(a[i],i));
    }
    sort(tmp.begin(),tmp.end());
    int cnt = 1;
    for (int i = 0; i < tmp.size(); i++) posinIT[tmp[i].second] = i+1;
    int lis = 0;
    for (int i = n; i >= 1; i--) {
        int pos = lower_bound(L,L + lis, -a[i]) - L;
        L[pos] = -a[i];
        res1[i] = pos + 1;
        update(1,1,n,posinIT[i],res1[i]);
        lis = max(lis, pos + 1);
    }
    for (int i = 1; i <= n; i++) a[i] -= X;
    lis = 0;
    for (int i = 1; i <= n; i++) {
        int pos = lower_bound(L,L + lis, a[i]) - L;
        L[pos] = a[i];
        res2[i] = pos + 1;
        lis = max(lis, pos + 1);
    }
    int res = res2[n];
    for (int i = 1; i <= n; i++) {
        pii A = pii(a[i],INF);
        update(1,1,n,posinIT[i], -INF);
        int l = upper_bound(tmp.begin(),tmp.end(),A) - tmp.begin() + 1;
        int cur = max(0,getMax(1,1,n, l, n));
        res = max(res,cur + res2[i]);
    }
    cout << res;
    return 0;
}

/*
5 100
100 100 1 1 3
*/

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = 0; i < tmp.size(); i++) posinIT[tmp[i].second] = i+1;
      |                     ~~^~~~~~~~~~~~
glo.cpp:40:9: warning: unused variable 'cnt' [-Wunused-variable]
   40 |     int cnt = 1;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 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 328 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 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 328 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 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 0 ms 328 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 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 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 328 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 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 0 ms 328 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 332 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 7156 KB Output is correct
2 Correct 193 ms 7164 KB Output is correct
3 Correct 184 ms 7100 KB Output is correct
4 Correct 186 ms 7080 KB Output is correct
5 Correct 114 ms 7500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 2124 KB Output is correct
2 Correct 42 ms 2124 KB Output is correct
3 Correct 42 ms 2124 KB Output is correct
4 Correct 25 ms 2252 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 28 ms 2508 KB Output is correct
7 Correct 36 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 3800 KB Output is correct
2 Correct 63 ms 3772 KB Output is correct
3 Correct 129 ms 7164 KB Output is correct
4 Correct 86 ms 7476 KB Output is correct
5 Correct 40 ms 4596 KB Output is correct
6 Correct 81 ms 8544 KB Output is correct
7 Correct 82 ms 9292 KB Output is correct
8 Correct 54 ms 4808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 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 328 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 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 0 ms 328 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 332 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 204 ms 7156 KB Output is correct
28 Correct 193 ms 7164 KB Output is correct
29 Correct 184 ms 7100 KB Output is correct
30 Correct 186 ms 7080 KB Output is correct
31 Correct 114 ms 7500 KB Output is correct
32 Correct 40 ms 2124 KB Output is correct
33 Correct 42 ms 2124 KB Output is correct
34 Correct 42 ms 2124 KB Output is correct
35 Correct 25 ms 2252 KB Output is correct
36 Correct 0 ms 324 KB Output is correct
37 Correct 28 ms 2508 KB Output is correct
38 Correct 36 ms 2640 KB Output is correct
39 Correct 62 ms 3800 KB Output is correct
40 Correct 63 ms 3772 KB Output is correct
41 Correct 129 ms 7164 KB Output is correct
42 Correct 86 ms 7476 KB Output is correct
43 Correct 40 ms 4596 KB Output is correct
44 Correct 81 ms 8544 KB Output is correct
45 Correct 82 ms 9292 KB Output is correct
46 Correct 54 ms 4808 KB Output is correct
47 Correct 87 ms 4804 KB Output is correct
48 Correct 90 ms 4800 KB Output is correct
49 Correct 191 ms 9144 KB Output is correct
50 Correct 105 ms 8632 KB Output is correct
51 Correct 76 ms 7252 KB Output is correct
52 Correct 119 ms 8760 KB Output is correct
53 Correct 76 ms 8916 KB Output is correct
54 Correct 82 ms 9536 KB Output is correct
55 Correct 154 ms 9040 KB Output is correct