#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);
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];
}
while (j < q) {
res[y[j].second] = flights;
j++;
}
for (long long f : res) {
cout << f << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 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 |
0 ms |
348 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 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 |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 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 |
22 ms |
2660 KB |
Output is correct |
2 |
Correct |
23 ms |
2748 KB |
Output is correct |
3 |
Correct |
20 ms |
2420 KB |
Output is correct |
4 |
Correct |
27 ms |
2448 KB |
Output is correct |
5 |
Correct |
21 ms |
2436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
5000 KB |
Output is correct |
2 |
Correct |
120 ms |
4992 KB |
Output is correct |
3 |
Correct |
122 ms |
5000 KB |
Output is correct |
4 |
Correct |
132 ms |
4960 KB |
Output is correct |
5 |
Correct |
119 ms |
4960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
4960 KB |
Output is correct |
2 |
Correct |
139 ms |
4976 KB |
Output is correct |
3 |
Correct |
126 ms |
5012 KB |
Output is correct |
4 |
Correct |
120 ms |
5192 KB |
Output is correct |
5 |
Correct |
146 ms |
5044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
22 ms |
2660 KB |
Output is correct |
12 |
Correct |
23 ms |
2748 KB |
Output is correct |
13 |
Correct |
20 ms |
2420 KB |
Output is correct |
14 |
Correct |
27 ms |
2448 KB |
Output is correct |
15 |
Correct |
21 ms |
2436 KB |
Output is correct |
16 |
Correct |
23 ms |
2436 KB |
Output is correct |
17 |
Correct |
25 ms |
2652 KB |
Output is correct |
18 |
Correct |
25 ms |
2752 KB |
Output is correct |
19 |
Correct |
22 ms |
2448 KB |
Output is correct |
20 |
Correct |
25 ms |
2488 KB |
Output is correct |
21 |
Correct |
23 ms |
2496 KB |
Output is correct |
22 |
Correct |
24 ms |
2440 KB |
Output is correct |
23 |
Correct |
24 ms |
2780 KB |
Output is correct |
24 |
Correct |
23 ms |
2472 KB |
Output is correct |
25 |
Correct |
24 ms |
2664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 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 |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 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 |
22 ms |
2660 KB |
Output is correct |
27 |
Correct |
23 ms |
2748 KB |
Output is correct |
28 |
Correct |
20 ms |
2420 KB |
Output is correct |
29 |
Correct |
27 ms |
2448 KB |
Output is correct |
30 |
Correct |
21 ms |
2436 KB |
Output is correct |
31 |
Correct |
117 ms |
5000 KB |
Output is correct |
32 |
Correct |
120 ms |
4992 KB |
Output is correct |
33 |
Correct |
122 ms |
5000 KB |
Output is correct |
34 |
Correct |
132 ms |
4960 KB |
Output is correct |
35 |
Correct |
119 ms |
4960 KB |
Output is correct |
36 |
Correct |
127 ms |
4960 KB |
Output is correct |
37 |
Correct |
139 ms |
4976 KB |
Output is correct |
38 |
Correct |
126 ms |
5012 KB |
Output is correct |
39 |
Correct |
120 ms |
5192 KB |
Output is correct |
40 |
Correct |
146 ms |
5044 KB |
Output is correct |
41 |
Correct |
23 ms |
2436 KB |
Output is correct |
42 |
Correct |
25 ms |
2652 KB |
Output is correct |
43 |
Correct |
25 ms |
2752 KB |
Output is correct |
44 |
Correct |
22 ms |
2448 KB |
Output is correct |
45 |
Correct |
25 ms |
2488 KB |
Output is correct |
46 |
Correct |
23 ms |
2496 KB |
Output is correct |
47 |
Correct |
24 ms |
2440 KB |
Output is correct |
48 |
Correct |
24 ms |
2780 KB |
Output is correct |
49 |
Correct |
23 ms |
2472 KB |
Output is correct |
50 |
Correct |
24 ms |
2664 KB |
Output is correct |
51 |
Correct |
145 ms |
4960 KB |
Output is correct |
52 |
Correct |
139 ms |
4724 KB |
Output is correct |
53 |
Correct |
124 ms |
4788 KB |
Output is correct |
54 |
Correct |
136 ms |
4716 KB |
Output is correct |
55 |
Correct |
123 ms |
4788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 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 |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 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 |
22 ms |
2660 KB |
Output is correct |
27 |
Correct |
23 ms |
2748 KB |
Output is correct |
28 |
Correct |
20 ms |
2420 KB |
Output is correct |
29 |
Correct |
27 ms |
2448 KB |
Output is correct |
30 |
Correct |
21 ms |
2436 KB |
Output is correct |
31 |
Correct |
117 ms |
5000 KB |
Output is correct |
32 |
Correct |
120 ms |
4992 KB |
Output is correct |
33 |
Correct |
122 ms |
5000 KB |
Output is correct |
34 |
Correct |
132 ms |
4960 KB |
Output is correct |
35 |
Correct |
119 ms |
4960 KB |
Output is correct |
36 |
Correct |
127 ms |
4960 KB |
Output is correct |
37 |
Correct |
139 ms |
4976 KB |
Output is correct |
38 |
Correct |
126 ms |
5012 KB |
Output is correct |
39 |
Correct |
120 ms |
5192 KB |
Output is correct |
40 |
Correct |
146 ms |
5044 KB |
Output is correct |
41 |
Correct |
23 ms |
2436 KB |
Output is correct |
42 |
Correct |
25 ms |
2652 KB |
Output is correct |
43 |
Correct |
25 ms |
2752 KB |
Output is correct |
44 |
Correct |
22 ms |
2448 KB |
Output is correct |
45 |
Correct |
25 ms |
2488 KB |
Output is correct |
46 |
Correct |
23 ms |
2496 KB |
Output is correct |
47 |
Correct |
24 ms |
2440 KB |
Output is correct |
48 |
Correct |
24 ms |
2780 KB |
Output is correct |
49 |
Correct |
23 ms |
2472 KB |
Output is correct |
50 |
Correct |
24 ms |
2664 KB |
Output is correct |
51 |
Correct |
145 ms |
4960 KB |
Output is correct |
52 |
Correct |
139 ms |
4724 KB |
Output is correct |
53 |
Correct |
124 ms |
4788 KB |
Output is correct |
54 |
Correct |
136 ms |
4716 KB |
Output is correct |
55 |
Correct |
123 ms |
4788 KB |
Output is correct |
56 |
Execution timed out |
1020 ms |
42928 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |