1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <iostream>
#include <vector>
#include <algorithm>
#define MAXX 1000001
using namespace std;
typedef long long ll;
ll a[MAXX], res[MAXX];
typedef pair<int, int> pp;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int max_idx = 0;
for (int i = 0; i < n; i++) res[i] = -1000000001;
vector<pp> ans;
for (int i = 0; i < n; i++) {
if (a[i] > res[max_idx]) {
res[++max_idx] = a[i];
ans.push_back(pp(max_idx, a[i]));
}
else {
int idx = lower_bound(res, res + max_idx, a[i]) - res;
res[idx] = a[i];
ans.push_back(pp(idx, a[i]));
}
}
cout << "debug " << '\n';
for (int i = 0; i < ans.size(); i++) cout << ans[i].first << " " << ans[i].second << ' ';
cout << '\n';
cout << max_idx << '\n';
int cnt = max_idx;
vector<int> real_ans;
for (int i = ans.size() - 1; i >= 0; i--) {
if (cnt == ans[i].first) {
real_ans.push_back(ans[i].second);
cnt--;
}
}
for (int i = real_ans.size() - 1; i >= 0; i--) cout << real_ans[i] << ' ';
cout << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
BOJ/C++