#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<pair<int, int>> h(n + 1);
for (int i = 1; i <= n; i++) {
cin >> h[i].first;
h[i].second = i;
}
sort(h.begin(), h.end());
h.push_back({1e6 + 1, n + 1});
vector<pair<int, int>> y(q);
for (int i = 0; i < q; i++) {
cin >> y[i].first;
y[i].second = i;
}
sort(y.begin(), y.end());
vector<long long> l(n + 2);
vector<long long> r(n + 2);
vector<long long> res(q, -1);
long long flights = 0;
int j = 0;
for (int i = 1; i <= n; i++) {
while (j < q && h[i].first > y[j].first) {
res[y[j].second] = flights;
j++;
}
int index = h[i].second;
l[index] = l[index - 1] + 1;
r[index] = r[index + 1] + 1;
if (r[index] > 1) {
l[index + r[index] - 1] += l[index];
}
if (l[index] > 1) {
r[index - l[index] + 1] += r[index];
}
flights += l[index] * r[index];
}
for (long long v : res) {
cout << (v >= 0 ? v : flights) << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2488 KB |
Output is correct |
2 |
Correct |
27 ms |
2648 KB |
Output is correct |
3 |
Correct |
24 ms |
2484 KB |
Output is correct |
4 |
Correct |
23 ms |
2492 KB |
Output is correct |
5 |
Correct |
22 ms |
2428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
4980 KB |
Output is correct |
2 |
Correct |
136 ms |
4980 KB |
Output is correct |
3 |
Correct |
127 ms |
4996 KB |
Output is correct |
4 |
Correct |
131 ms |
4996 KB |
Output is correct |
5 |
Correct |
147 ms |
4964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
4964 KB |
Output is correct |
2 |
Correct |
134 ms |
4992 KB |
Output is correct |
3 |
Correct |
137 ms |
5044 KB |
Output is correct |
4 |
Correct |
131 ms |
4936 KB |
Output is correct |
5 |
Correct |
143 ms |
4980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
23 ms |
2488 KB |
Output is correct |
12 |
Correct |
27 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
2484 KB |
Output is correct |
14 |
Correct |
23 ms |
2492 KB |
Output is correct |
15 |
Correct |
22 ms |
2428 KB |
Output is correct |
16 |
Correct |
22 ms |
2472 KB |
Output is correct |
17 |
Correct |
25 ms |
2488 KB |
Output is correct |
18 |
Correct |
25 ms |
2740 KB |
Output is correct |
19 |
Correct |
22 ms |
2440 KB |
Output is correct |
20 |
Correct |
25 ms |
2660 KB |
Output is correct |
21 |
Correct |
22 ms |
2448 KB |
Output is correct |
22 |
Correct |
23 ms |
2496 KB |
Output is correct |
23 |
Correct |
27 ms |
2644 KB |
Output is correct |
24 |
Correct |
25 ms |
2496 KB |
Output is correct |
25 |
Correct |
23 ms |
2480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
23 ms |
2488 KB |
Output is correct |
27 |
Correct |
27 ms |
2648 KB |
Output is correct |
28 |
Correct |
24 ms |
2484 KB |
Output is correct |
29 |
Correct |
23 ms |
2492 KB |
Output is correct |
30 |
Correct |
22 ms |
2428 KB |
Output is correct |
31 |
Correct |
129 ms |
4980 KB |
Output is correct |
32 |
Correct |
136 ms |
4980 KB |
Output is correct |
33 |
Correct |
127 ms |
4996 KB |
Output is correct |
34 |
Correct |
131 ms |
4996 KB |
Output is correct |
35 |
Correct |
147 ms |
4964 KB |
Output is correct |
36 |
Correct |
158 ms |
4964 KB |
Output is correct |
37 |
Correct |
134 ms |
4992 KB |
Output is correct |
38 |
Correct |
137 ms |
5044 KB |
Output is correct |
39 |
Correct |
131 ms |
4936 KB |
Output is correct |
40 |
Correct |
143 ms |
4980 KB |
Output is correct |
41 |
Correct |
22 ms |
2472 KB |
Output is correct |
42 |
Correct |
25 ms |
2488 KB |
Output is correct |
43 |
Correct |
25 ms |
2740 KB |
Output is correct |
44 |
Correct |
22 ms |
2440 KB |
Output is correct |
45 |
Correct |
25 ms |
2660 KB |
Output is correct |
46 |
Correct |
22 ms |
2448 KB |
Output is correct |
47 |
Correct |
23 ms |
2496 KB |
Output is correct |
48 |
Correct |
27 ms |
2644 KB |
Output is correct |
49 |
Correct |
25 ms |
2496 KB |
Output is correct |
50 |
Correct |
23 ms |
2480 KB |
Output is correct |
51 |
Correct |
137 ms |
4964 KB |
Output is correct |
52 |
Correct |
144 ms |
4724 KB |
Output is correct |
53 |
Correct |
145 ms |
4784 KB |
Output is correct |
54 |
Correct |
139 ms |
4712 KB |
Output is correct |
55 |
Correct |
138 ms |
4996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
23 ms |
2488 KB |
Output is correct |
27 |
Correct |
27 ms |
2648 KB |
Output is correct |
28 |
Correct |
24 ms |
2484 KB |
Output is correct |
29 |
Correct |
23 ms |
2492 KB |
Output is correct |
30 |
Correct |
22 ms |
2428 KB |
Output is correct |
31 |
Correct |
129 ms |
4980 KB |
Output is correct |
32 |
Correct |
136 ms |
4980 KB |
Output is correct |
33 |
Correct |
127 ms |
4996 KB |
Output is correct |
34 |
Correct |
131 ms |
4996 KB |
Output is correct |
35 |
Correct |
147 ms |
4964 KB |
Output is correct |
36 |
Correct |
158 ms |
4964 KB |
Output is correct |
37 |
Correct |
134 ms |
4992 KB |
Output is correct |
38 |
Correct |
137 ms |
5044 KB |
Output is correct |
39 |
Correct |
131 ms |
4936 KB |
Output is correct |
40 |
Correct |
143 ms |
4980 KB |
Output is correct |
41 |
Correct |
22 ms |
2472 KB |
Output is correct |
42 |
Correct |
25 ms |
2488 KB |
Output is correct |
43 |
Correct |
25 ms |
2740 KB |
Output is correct |
44 |
Correct |
22 ms |
2440 KB |
Output is correct |
45 |
Correct |
25 ms |
2660 KB |
Output is correct |
46 |
Correct |
22 ms |
2448 KB |
Output is correct |
47 |
Correct |
23 ms |
2496 KB |
Output is correct |
48 |
Correct |
27 ms |
2644 KB |
Output is correct |
49 |
Correct |
25 ms |
2496 KB |
Output is correct |
50 |
Correct |
23 ms |
2480 KB |
Output is correct |
51 |
Correct |
137 ms |
4964 KB |
Output is correct |
52 |
Correct |
144 ms |
4724 KB |
Output is correct |
53 |
Correct |
145 ms |
4784 KB |
Output is correct |
54 |
Correct |
139 ms |
4712 KB |
Output is correct |
55 |
Correct |
138 ms |
4996 KB |
Output is correct |
56 |
Execution timed out |
1028 ms |
43688 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |