#include <iostream>
#include <vector>
using namespace std;
struct mountain {
int height;
int index;
};
//vector<long long> count(vector<int> h, vector<int> y) { // i would have written like that, but ive had no idea, how to make it faster
void count(vector<int> h, int q) {
h.push_back(1000001); // last border
vector<mountain> border;
border.push_back({1000002, -1}); // blocker
vector<long long> allPlanes(1000001);
for (int i = 0; i < h.size(); i++) {
for (;h[i] >= border.back().height; border.pop_back()) { // remove last border
long long a = (i - border.back().index), b = (border.back().index - border[border.size() - 2].index);
allPlanes[border.back().height] += a * b; // add possible flights to last border mountain height velocity plane
// starting before or with last border * ending after or with last border
}
border.push_back({h[i], i}); // add border
}
for (int i = 2; i < allPlanes.size(); i++) { // partial sum of possible flights
allPlanes[i] += allPlanes[i - 1];
}
/*vector<long long> result;
for (int Y : y) { // filling up queries
if (Y >= allPlanes.size()) {
result.push_back(allPlanes.back());
}else {
result.push_back(allPlanes[Y]);
}
}
return result;*/
int Y;
for (int i = 0; i < q; i++) { // filling up queries
cin >> Y;
if (Y >= allPlanes.size()) {
cout << allPlanes.back() << endl;
}else {
cout << allPlanes[Y] << endl;
}
}
return;
}
int main() {
int n, q;
cin >> n >> q;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
count(h, q);
/*vector<int> y(q);
for (int i = 0; i < q; i++) {
cin >> y[i];
}
for (long long r : count(h, y)) {
cout << r << endl;
}*/
return 0;
}
Compilation message
pilot.cpp: In function 'void count(std::vector<int>, int)':
pilot.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < h.size(); i++) {
| ~~^~~~~~~~~~
pilot.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = 2; i < allPlanes.size(); i++) { // partial sum of possible flights
| ~~^~~~~~~~~~~~~~~~~~
pilot.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if (Y >= allPlanes.size()) {
| ~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8028 KB |
Output is correct |
12 |
Correct |
4 ms |
8120 KB |
Output is correct |
13 |
Correct |
5 ms |
8028 KB |
Output is correct |
14 |
Correct |
4 ms |
8028 KB |
Output is correct |
15 |
Correct |
4 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8028 KB |
Output is correct |
12 |
Correct |
4 ms |
8120 KB |
Output is correct |
13 |
Correct |
5 ms |
8028 KB |
Output is correct |
14 |
Correct |
4 ms |
8028 KB |
Output is correct |
15 |
Correct |
4 ms |
8280 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8112 KB |
Output is correct |
18 |
Correct |
4 ms |
8276 KB |
Output is correct |
19 |
Correct |
4 ms |
8280 KB |
Output is correct |
20 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8028 KB |
Output is correct |
12 |
Correct |
4 ms |
8120 KB |
Output is correct |
13 |
Correct |
5 ms |
8028 KB |
Output is correct |
14 |
Correct |
4 ms |
8028 KB |
Output is correct |
15 |
Correct |
4 ms |
8280 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8112 KB |
Output is correct |
18 |
Correct |
4 ms |
8276 KB |
Output is correct |
19 |
Correct |
4 ms |
8280 KB |
Output is correct |
20 |
Correct |
4 ms |
8284 KB |
Output is correct |
21 |
Correct |
5 ms |
8284 KB |
Output is correct |
22 |
Correct |
6 ms |
8284 KB |
Output is correct |
23 |
Correct |
6 ms |
8284 KB |
Output is correct |
24 |
Correct |
6 ms |
8284 KB |
Output is correct |
25 |
Correct |
5 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
9448 KB |
Output is correct |
2 |
Correct |
27 ms |
9588 KB |
Output is correct |
3 |
Correct |
24 ms |
9708 KB |
Output is correct |
4 |
Correct |
24 ms |
9384 KB |
Output is correct |
5 |
Correct |
20 ms |
9456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
11040 KB |
Output is correct |
2 |
Correct |
140 ms |
10984 KB |
Output is correct |
3 |
Correct |
147 ms |
11028 KB |
Output is correct |
4 |
Correct |
135 ms |
10968 KB |
Output is correct |
5 |
Correct |
127 ms |
10992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
10972 KB |
Output is correct |
2 |
Correct |
136 ms |
11196 KB |
Output is correct |
3 |
Correct |
143 ms |
10992 KB |
Output is correct |
4 |
Correct |
135 ms |
11204 KB |
Output is correct |
5 |
Correct |
168 ms |
11300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
21 ms |
9448 KB |
Output is correct |
12 |
Correct |
27 ms |
9588 KB |
Output is correct |
13 |
Correct |
24 ms |
9708 KB |
Output is correct |
14 |
Correct |
24 ms |
9384 KB |
Output is correct |
15 |
Correct |
20 ms |
9456 KB |
Output is correct |
16 |
Correct |
20 ms |
9456 KB |
Output is correct |
17 |
Correct |
24 ms |
9680 KB |
Output is correct |
18 |
Correct |
23 ms |
9684 KB |
Output is correct |
19 |
Correct |
19 ms |
9524 KB |
Output is correct |
20 |
Correct |
37 ms |
9436 KB |
Output is correct |
21 |
Correct |
20 ms |
9460 KB |
Output is correct |
22 |
Correct |
27 ms |
9452 KB |
Output is correct |
23 |
Correct |
21 ms |
9432 KB |
Output is correct |
24 |
Correct |
29 ms |
9496 KB |
Output is correct |
25 |
Correct |
21 ms |
9432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8028 KB |
Output is correct |
12 |
Correct |
4 ms |
8120 KB |
Output is correct |
13 |
Correct |
5 ms |
8028 KB |
Output is correct |
14 |
Correct |
4 ms |
8028 KB |
Output is correct |
15 |
Correct |
4 ms |
8280 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8112 KB |
Output is correct |
18 |
Correct |
4 ms |
8276 KB |
Output is correct |
19 |
Correct |
4 ms |
8280 KB |
Output is correct |
20 |
Correct |
4 ms |
8284 KB |
Output is correct |
21 |
Correct |
5 ms |
8284 KB |
Output is correct |
22 |
Correct |
6 ms |
8284 KB |
Output is correct |
23 |
Correct |
6 ms |
8284 KB |
Output is correct |
24 |
Correct |
6 ms |
8284 KB |
Output is correct |
25 |
Correct |
5 ms |
8284 KB |
Output is correct |
26 |
Correct |
21 ms |
9448 KB |
Output is correct |
27 |
Correct |
27 ms |
9588 KB |
Output is correct |
28 |
Correct |
24 ms |
9708 KB |
Output is correct |
29 |
Correct |
24 ms |
9384 KB |
Output is correct |
30 |
Correct |
20 ms |
9456 KB |
Output is correct |
31 |
Correct |
139 ms |
11040 KB |
Output is correct |
32 |
Correct |
140 ms |
10984 KB |
Output is correct |
33 |
Correct |
147 ms |
11028 KB |
Output is correct |
34 |
Correct |
135 ms |
10968 KB |
Output is correct |
35 |
Correct |
127 ms |
10992 KB |
Output is correct |
36 |
Correct |
131 ms |
10972 KB |
Output is correct |
37 |
Correct |
136 ms |
11196 KB |
Output is correct |
38 |
Correct |
143 ms |
10992 KB |
Output is correct |
39 |
Correct |
135 ms |
11204 KB |
Output is correct |
40 |
Correct |
168 ms |
11300 KB |
Output is correct |
41 |
Correct |
20 ms |
9456 KB |
Output is correct |
42 |
Correct |
24 ms |
9680 KB |
Output is correct |
43 |
Correct |
23 ms |
9684 KB |
Output is correct |
44 |
Correct |
19 ms |
9524 KB |
Output is correct |
45 |
Correct |
37 ms |
9436 KB |
Output is correct |
46 |
Correct |
20 ms |
9460 KB |
Output is correct |
47 |
Correct |
27 ms |
9452 KB |
Output is correct |
48 |
Correct |
21 ms |
9432 KB |
Output is correct |
49 |
Correct |
29 ms |
9496 KB |
Output is correct |
50 |
Correct |
21 ms |
9432 KB |
Output is correct |
51 |
Correct |
143 ms |
10912 KB |
Output is correct |
52 |
Correct |
195 ms |
10720 KB |
Output is correct |
53 |
Correct |
141 ms |
10964 KB |
Output is correct |
54 |
Correct |
139 ms |
10720 KB |
Output is correct |
55 |
Correct |
135 ms |
10956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8280 KB |
Output is correct |
2 |
Correct |
4 ms |
8028 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
4 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8284 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
4 ms |
8284 KB |
Output is correct |
9 |
Correct |
4 ms |
8284 KB |
Output is correct |
10 |
Correct |
4 ms |
8284 KB |
Output is correct |
11 |
Correct |
4 ms |
8028 KB |
Output is correct |
12 |
Correct |
4 ms |
8120 KB |
Output is correct |
13 |
Correct |
5 ms |
8028 KB |
Output is correct |
14 |
Correct |
4 ms |
8028 KB |
Output is correct |
15 |
Correct |
4 ms |
8280 KB |
Output is correct |
16 |
Correct |
4 ms |
8284 KB |
Output is correct |
17 |
Correct |
4 ms |
8112 KB |
Output is correct |
18 |
Correct |
4 ms |
8276 KB |
Output is correct |
19 |
Correct |
4 ms |
8280 KB |
Output is correct |
20 |
Correct |
4 ms |
8284 KB |
Output is correct |
21 |
Correct |
5 ms |
8284 KB |
Output is correct |
22 |
Correct |
6 ms |
8284 KB |
Output is correct |
23 |
Correct |
6 ms |
8284 KB |
Output is correct |
24 |
Correct |
6 ms |
8284 KB |
Output is correct |
25 |
Correct |
5 ms |
8284 KB |
Output is correct |
26 |
Correct |
21 ms |
9448 KB |
Output is correct |
27 |
Correct |
27 ms |
9588 KB |
Output is correct |
28 |
Correct |
24 ms |
9708 KB |
Output is correct |
29 |
Correct |
24 ms |
9384 KB |
Output is correct |
30 |
Correct |
20 ms |
9456 KB |
Output is correct |
31 |
Correct |
139 ms |
11040 KB |
Output is correct |
32 |
Correct |
140 ms |
10984 KB |
Output is correct |
33 |
Correct |
147 ms |
11028 KB |
Output is correct |
34 |
Correct |
135 ms |
10968 KB |
Output is correct |
35 |
Correct |
127 ms |
10992 KB |
Output is correct |
36 |
Correct |
131 ms |
10972 KB |
Output is correct |
37 |
Correct |
136 ms |
11196 KB |
Output is correct |
38 |
Correct |
143 ms |
10992 KB |
Output is correct |
39 |
Correct |
135 ms |
11204 KB |
Output is correct |
40 |
Correct |
168 ms |
11300 KB |
Output is correct |
41 |
Correct |
20 ms |
9456 KB |
Output is correct |
42 |
Correct |
24 ms |
9680 KB |
Output is correct |
43 |
Correct |
23 ms |
9684 KB |
Output is correct |
44 |
Correct |
19 ms |
9524 KB |
Output is correct |
45 |
Correct |
37 ms |
9436 KB |
Output is correct |
46 |
Correct |
20 ms |
9460 KB |
Output is correct |
47 |
Correct |
27 ms |
9452 KB |
Output is correct |
48 |
Correct |
21 ms |
9432 KB |
Output is correct |
49 |
Correct |
29 ms |
9496 KB |
Output is correct |
50 |
Correct |
21 ms |
9432 KB |
Output is correct |
51 |
Correct |
143 ms |
10912 KB |
Output is correct |
52 |
Correct |
195 ms |
10720 KB |
Output is correct |
53 |
Correct |
141 ms |
10964 KB |
Output is correct |
54 |
Correct |
139 ms |
10720 KB |
Output is correct |
55 |
Correct |
135 ms |
10956 KB |
Output is correct |
56 |
Execution timed out |
1082 ms |
33024 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |