답안 #547237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547237 2022-04-10T01:37:21 Z DP_196 Global Warming (CEOI18_glo) C++14
100 / 100
123 ms 7368 KB
#include<bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
const int INF = (int) 1e9 + 7;
int n, d, a[N], dp1[N], dp2[N], tmp[N], bit[N], c[N], res;
vector<int> b;

struct BIT {
    void update(int id, int val) {
        for (; id; id -= (id & (-id))) bit[id] = max(bit[id], val);
    }

    int get(int id) {
        int res = 0;
        for (; id <= n; id += (id & (-id))) res =  max(res, bit[id]);
        return res;
    }
}  myBit;

void init() {
    for (int i = 1; i <= n; i++) {
        dp1[i] = lower_bound(tmp + 1, tmp + res + 1, a[i]) - tmp;
        res = max(res, dp1[i]);
        tmp[dp1[i]] = a[i];
    }

    for (int i = n; i >= 1; --i) {
    	dp2[i] = myBit.get(c[i] + 1) + 1;
    	myBit.update(c[i], dp2[i]);
    }
}

#define TASK "LIS"
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    if (fopen(TASK".inp","r")) {
        freopen(TASK".inp","r",stdin);
        freopen(TASK".out","w",stdout);
    }

    cin >> n >> d;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b.push_back(a[i]);
    }

    sort(b.begin(), b.end());
    for (int i = 1; i <= n; i++) c[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
    init();

    int result = 0;
    memset(bit, 0, sizeof bit);
    myBit.update(c[n], dp2[n]);

    for (int i = n - 1; i >= 1; i--) {
        int pos = upper_bound(b.begin(), b.end(), a[i] - d) - b.begin() + 1;
        result = max(result, dp1[i] + myBit.get(pos));
        myBit.update(c[i], dp2[i]);
    }

    cout << result;
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(TASK".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(TASK".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1096 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1096 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1108 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 6996 KB Output is correct
2 Correct 116 ms 7012 KB Output is correct
3 Correct 123 ms 6956 KB Output is correct
4 Correct 114 ms 6980 KB Output is correct
5 Correct 56 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2688 KB Output is correct
2 Correct 27 ms 2660 KB Output is correct
3 Correct 28 ms 2796 KB Output is correct
4 Correct 13 ms 2572 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 14 ms 2644 KB Output is correct
7 Correct 22 ms 2632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 4064 KB Output is correct
2 Correct 42 ms 4072 KB Output is correct
3 Correct 90 ms 6984 KB Output is correct
4 Correct 57 ms 6652 KB Output is correct
5 Correct 27 ms 3960 KB Output is correct
6 Correct 48 ms 6408 KB Output is correct
7 Correct 52 ms 7200 KB Output is correct
8 Correct 36 ms 4148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1096 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1108 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 122 ms 6996 KB Output is correct
28 Correct 116 ms 7012 KB Output is correct
29 Correct 123 ms 6956 KB Output is correct
30 Correct 114 ms 6980 KB Output is correct
31 Correct 56 ms 6656 KB Output is correct
32 Correct 27 ms 2688 KB Output is correct
33 Correct 27 ms 2660 KB Output is correct
34 Correct 28 ms 2796 KB Output is correct
35 Correct 13 ms 2572 KB Output is correct
36 Correct 1 ms 1108 KB Output is correct
37 Correct 14 ms 2644 KB Output is correct
38 Correct 22 ms 2632 KB Output is correct
39 Correct 45 ms 4064 KB Output is correct
40 Correct 42 ms 4072 KB Output is correct
41 Correct 90 ms 6984 KB Output is correct
42 Correct 57 ms 6652 KB Output is correct
43 Correct 27 ms 3960 KB Output is correct
44 Correct 48 ms 6408 KB Output is correct
45 Correct 52 ms 7200 KB Output is correct
46 Correct 36 ms 4148 KB Output is correct
47 Correct 54 ms 4172 KB Output is correct
48 Correct 54 ms 4172 KB Output is correct
49 Correct 115 ms 7028 KB Output is correct
50 Correct 56 ms 6696 KB Output is correct
51 Correct 47 ms 5396 KB Output is correct
52 Correct 67 ms 6780 KB Output is correct
53 Correct 50 ms 6776 KB Output is correct
54 Correct 53 ms 7368 KB Output is correct
55 Correct 97 ms 7048 KB Output is correct