#include <bits/stdc++.h>
using i64 = long long;
i64 c2(i64 x) {
return x * (x + 1) / 2;
}
void solve() {
int N, Q;
std::cin >> N >> Q;
std::vector<int> H(N), Y(Q);
for (auto &e : H) std::cin >> e;
for (auto &e : Y) std::cin >> e;
std::vector<std::pair<int, int>> queries(Q);
for (int i = 0; i < Q; ++i) queries[i] = {Y[i], i};
std::sort(queries.begin(), queries.end());
std::vector<std::pair<int, int>> mountains(N);
for (int i = 0; i < N; ++i) mountains[i] = {H[i], i};
std::sort(mountains.begin(), mountains.end());
std::set<int> s;
s.insert(-1);
s.insert(N);
int j = 0;
for (int i = 0; i < N; ++i) s.insert(i);
std::vector<i64> answer(Q);
i64 countFlights = 0;
for (int i = 0; i < N; ++i) {
while (j != Q and queries[j].first < mountains[i].first) {
answer[queries[j].second] = countFlights;
++j;
}
auto itr = s.lower_bound(mountains[i].second);
auto itrL = itr;
--itrL;
auto itrR = itr;
++itrR;
countFlights -= c2(*itrR - *itr - 1);
countFlights -= c2(*itr - *itrL - 1);
countFlights += c2(*itrR - *itrL - 1);
s.erase(itr);
}
while (j != Q) {
answer[queries[j].second] = countFlights;
++j;
}
for (const auto e : answer) std::cout << e << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
6524 KB |
Output is correct |
2 |
Correct |
61 ms |
6744 KB |
Output is correct |
3 |
Correct |
70 ms |
6328 KB |
Output is correct |
4 |
Correct |
56 ms |
6212 KB |
Output is correct |
5 |
Correct |
57 ms |
6152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
9608 KB |
Output is correct |
2 |
Correct |
59 ms |
9696 KB |
Output is correct |
3 |
Correct |
57 ms |
9652 KB |
Output is correct |
4 |
Correct |
59 ms |
9868 KB |
Output is correct |
5 |
Correct |
54 ms |
9568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
9780 KB |
Output is correct |
2 |
Correct |
62 ms |
9700 KB |
Output is correct |
3 |
Correct |
56 ms |
9804 KB |
Output is correct |
4 |
Correct |
62 ms |
10096 KB |
Output is correct |
5 |
Correct |
63 ms |
10104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
59 ms |
6524 KB |
Output is correct |
12 |
Correct |
61 ms |
6744 KB |
Output is correct |
13 |
Correct |
70 ms |
6328 KB |
Output is correct |
14 |
Correct |
56 ms |
6212 KB |
Output is correct |
15 |
Correct |
57 ms |
6152 KB |
Output is correct |
16 |
Correct |
56 ms |
6276 KB |
Output is correct |
17 |
Correct |
64 ms |
6696 KB |
Output is correct |
18 |
Correct |
60 ms |
6812 KB |
Output is correct |
19 |
Correct |
54 ms |
6220 KB |
Output is correct |
20 |
Correct |
63 ms |
6488 KB |
Output is correct |
21 |
Correct |
57 ms |
6204 KB |
Output is correct |
22 |
Correct |
60 ms |
6348 KB |
Output is correct |
23 |
Correct |
60 ms |
6716 KB |
Output is correct |
24 |
Correct |
57 ms |
6228 KB |
Output is correct |
25 |
Correct |
70 ms |
6476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
59 ms |
6524 KB |
Output is correct |
27 |
Correct |
61 ms |
6744 KB |
Output is correct |
28 |
Correct |
70 ms |
6328 KB |
Output is correct |
29 |
Correct |
56 ms |
6212 KB |
Output is correct |
30 |
Correct |
57 ms |
6152 KB |
Output is correct |
31 |
Correct |
54 ms |
9608 KB |
Output is correct |
32 |
Correct |
59 ms |
9696 KB |
Output is correct |
33 |
Correct |
57 ms |
9652 KB |
Output is correct |
34 |
Correct |
59 ms |
9868 KB |
Output is correct |
35 |
Correct |
54 ms |
9568 KB |
Output is correct |
36 |
Correct |
64 ms |
9780 KB |
Output is correct |
37 |
Correct |
62 ms |
9700 KB |
Output is correct |
38 |
Correct |
56 ms |
9804 KB |
Output is correct |
39 |
Correct |
62 ms |
10096 KB |
Output is correct |
40 |
Correct |
63 ms |
10104 KB |
Output is correct |
41 |
Correct |
56 ms |
6276 KB |
Output is correct |
42 |
Correct |
64 ms |
6696 KB |
Output is correct |
43 |
Correct |
60 ms |
6812 KB |
Output is correct |
44 |
Correct |
54 ms |
6220 KB |
Output is correct |
45 |
Correct |
63 ms |
6488 KB |
Output is correct |
46 |
Correct |
57 ms |
6204 KB |
Output is correct |
47 |
Correct |
60 ms |
6348 KB |
Output is correct |
48 |
Correct |
60 ms |
6716 KB |
Output is correct |
49 |
Correct |
57 ms |
6228 KB |
Output is correct |
50 |
Correct |
70 ms |
6476 KB |
Output is correct |
51 |
Correct |
83 ms |
9804 KB |
Output is correct |
52 |
Correct |
81 ms |
9684 KB |
Output is correct |
53 |
Correct |
88 ms |
9848 KB |
Output is correct |
54 |
Correct |
91 ms |
9620 KB |
Output is correct |
55 |
Correct |
84 ms |
9872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
59 ms |
6524 KB |
Output is correct |
27 |
Correct |
61 ms |
6744 KB |
Output is correct |
28 |
Correct |
70 ms |
6328 KB |
Output is correct |
29 |
Correct |
56 ms |
6212 KB |
Output is correct |
30 |
Correct |
57 ms |
6152 KB |
Output is correct |
31 |
Correct |
54 ms |
9608 KB |
Output is correct |
32 |
Correct |
59 ms |
9696 KB |
Output is correct |
33 |
Correct |
57 ms |
9652 KB |
Output is correct |
34 |
Correct |
59 ms |
9868 KB |
Output is correct |
35 |
Correct |
54 ms |
9568 KB |
Output is correct |
36 |
Correct |
64 ms |
9780 KB |
Output is correct |
37 |
Correct |
62 ms |
9700 KB |
Output is correct |
38 |
Correct |
56 ms |
9804 KB |
Output is correct |
39 |
Correct |
62 ms |
10096 KB |
Output is correct |
40 |
Correct |
63 ms |
10104 KB |
Output is correct |
41 |
Correct |
56 ms |
6276 KB |
Output is correct |
42 |
Correct |
64 ms |
6696 KB |
Output is correct |
43 |
Correct |
60 ms |
6812 KB |
Output is correct |
44 |
Correct |
54 ms |
6220 KB |
Output is correct |
45 |
Correct |
63 ms |
6488 KB |
Output is correct |
46 |
Correct |
57 ms |
6204 KB |
Output is correct |
47 |
Correct |
60 ms |
6348 KB |
Output is correct |
48 |
Correct |
60 ms |
6716 KB |
Output is correct |
49 |
Correct |
57 ms |
6228 KB |
Output is correct |
50 |
Correct |
70 ms |
6476 KB |
Output is correct |
51 |
Correct |
83 ms |
9804 KB |
Output is correct |
52 |
Correct |
81 ms |
9684 KB |
Output is correct |
53 |
Correct |
88 ms |
9848 KB |
Output is correct |
54 |
Correct |
91 ms |
9620 KB |
Output is correct |
55 |
Correct |
84 ms |
9872 KB |
Output is correct |
56 |
Execution timed out |
1057 ms |
87604 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |