-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtoi18_garden.cpp
44 lines (39 loc) · 990 Bytes
/
toi18_garden.cpp
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
/**
Longest Increasing Subsequence
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#define for_(i, k, n) for (int i = k; i < n; ++i)
#define all(x) x.begin(), x.end()
using namespace std;
using Vec = std::vector<int>;
Vec longest_increasing_subsequence(const Vec& inp) {
Vec res;
Vec dp;
for (int val : inp) {
auto it = std::lower_bound(all(dp), val);
res.push_back(it - dp.begin());
if (it != dp.end()) *it = val;
else dp.push_back(val);
}
assert(inp.size() == res.size());
return res;
}
int main() {
int n_input, n_question;
std::cin >> n_input >> n_question;
Vec inp(n_input);
for (int& val : inp) {
std::cin >> val;
}
Vec lis_forward = longest_increasing_subsequence(inp);
std::reverse(all(inp));
Vec lis_backward = longest_increasing_subsequence(inp);
while (n_question--) {
int i;
std::cin >> i;
std::cout << std::min(lis_forward[i], lis_backward[n_input-i-1]) << std::endl;
}
}