#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<int> l(n + 2);
vector<int> 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 |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
344 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
344 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
3 ms |
480 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1896 KB |
Output is correct |
2 |
Correct |
25 ms |
2388 KB |
Output is correct |
3 |
Correct |
21 ms |
2428 KB |
Output is correct |
4 |
Correct |
22 ms |
2332 KB |
Output is correct |
5 |
Correct |
21 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
4196 KB |
Output is correct |
2 |
Correct |
122 ms |
5344 KB |
Output is correct |
3 |
Correct |
120 ms |
5324 KB |
Output is correct |
4 |
Correct |
122 ms |
5364 KB |
Output is correct |
5 |
Correct |
129 ms |
5260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
4200 KB |
Output is correct |
2 |
Correct |
121 ms |
5500 KB |
Output is correct |
3 |
Correct |
132 ms |
5600 KB |
Output is correct |
4 |
Correct |
128 ms |
5536 KB |
Output is correct |
5 |
Correct |
145 ms |
5804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
21 ms |
1896 KB |
Output is correct |
12 |
Correct |
25 ms |
2388 KB |
Output is correct |
13 |
Correct |
21 ms |
2428 KB |
Output is correct |
14 |
Correct |
22 ms |
2332 KB |
Output is correct |
15 |
Correct |
21 ms |
2388 KB |
Output is correct |
16 |
Correct |
22 ms |
2220 KB |
Output is correct |
17 |
Correct |
24 ms |
2384 KB |
Output is correct |
18 |
Correct |
25 ms |
2652 KB |
Output is correct |
19 |
Correct |
23 ms |
2392 KB |
Output is correct |
20 |
Correct |
25 ms |
2600 KB |
Output is correct |
21 |
Correct |
22 ms |
2224 KB |
Output is correct |
22 |
Correct |
23 ms |
2440 KB |
Output is correct |
23 |
Correct |
27 ms |
2548 KB |
Output is correct |
24 |
Correct |
23 ms |
2340 KB |
Output is correct |
25 |
Correct |
23 ms |
2404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
344 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
3 ms |
480 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
360 KB |
Output is correct |
26 |
Correct |
21 ms |
1896 KB |
Output is correct |
27 |
Correct |
25 ms |
2388 KB |
Output is correct |
28 |
Correct |
21 ms |
2428 KB |
Output is correct |
29 |
Correct |
22 ms |
2332 KB |
Output is correct |
30 |
Correct |
21 ms |
2388 KB |
Output is correct |
31 |
Correct |
113 ms |
4196 KB |
Output is correct |
32 |
Correct |
122 ms |
5344 KB |
Output is correct |
33 |
Correct |
120 ms |
5324 KB |
Output is correct |
34 |
Correct |
122 ms |
5364 KB |
Output is correct |
35 |
Correct |
129 ms |
5260 KB |
Output is correct |
36 |
Correct |
116 ms |
4200 KB |
Output is correct |
37 |
Correct |
121 ms |
5500 KB |
Output is correct |
38 |
Correct |
132 ms |
5600 KB |
Output is correct |
39 |
Correct |
128 ms |
5536 KB |
Output is correct |
40 |
Correct |
145 ms |
5804 KB |
Output is correct |
41 |
Correct |
22 ms |
2220 KB |
Output is correct |
42 |
Correct |
24 ms |
2384 KB |
Output is correct |
43 |
Correct |
25 ms |
2652 KB |
Output is correct |
44 |
Correct |
23 ms |
2392 KB |
Output is correct |
45 |
Correct |
25 ms |
2600 KB |
Output is correct |
46 |
Correct |
22 ms |
2224 KB |
Output is correct |
47 |
Correct |
23 ms |
2440 KB |
Output is correct |
48 |
Correct |
27 ms |
2548 KB |
Output is correct |
49 |
Correct |
23 ms |
2340 KB |
Output is correct |
50 |
Correct |
23 ms |
2404 KB |
Output is correct |
51 |
Correct |
129 ms |
5224 KB |
Output is correct |
52 |
Correct |
138 ms |
5232 KB |
Output is correct |
53 |
Correct |
129 ms |
5368 KB |
Output is correct |
54 |
Correct |
133 ms |
5244 KB |
Output is correct |
55 |
Incorrect |
128 ms |
5200 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
344 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
3 ms |
480 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
360 KB |
Output is correct |
26 |
Correct |
21 ms |
1896 KB |
Output is correct |
27 |
Correct |
25 ms |
2388 KB |
Output is correct |
28 |
Correct |
21 ms |
2428 KB |
Output is correct |
29 |
Correct |
22 ms |
2332 KB |
Output is correct |
30 |
Correct |
21 ms |
2388 KB |
Output is correct |
31 |
Correct |
113 ms |
4196 KB |
Output is correct |
32 |
Correct |
122 ms |
5344 KB |
Output is correct |
33 |
Correct |
120 ms |
5324 KB |
Output is correct |
34 |
Correct |
122 ms |
5364 KB |
Output is correct |
35 |
Correct |
129 ms |
5260 KB |
Output is correct |
36 |
Correct |
116 ms |
4200 KB |
Output is correct |
37 |
Correct |
121 ms |
5500 KB |
Output is correct |
38 |
Correct |
132 ms |
5600 KB |
Output is correct |
39 |
Correct |
128 ms |
5536 KB |
Output is correct |
40 |
Correct |
145 ms |
5804 KB |
Output is correct |
41 |
Correct |
22 ms |
2220 KB |
Output is correct |
42 |
Correct |
24 ms |
2384 KB |
Output is correct |
43 |
Correct |
25 ms |
2652 KB |
Output is correct |
44 |
Correct |
23 ms |
2392 KB |
Output is correct |
45 |
Correct |
25 ms |
2600 KB |
Output is correct |
46 |
Correct |
22 ms |
2224 KB |
Output is correct |
47 |
Correct |
23 ms |
2440 KB |
Output is correct |
48 |
Correct |
27 ms |
2548 KB |
Output is correct |
49 |
Correct |
23 ms |
2340 KB |
Output is correct |
50 |
Correct |
23 ms |
2404 KB |
Output is correct |
51 |
Correct |
129 ms |
5224 KB |
Output is correct |
52 |
Correct |
138 ms |
5232 KB |
Output is correct |
53 |
Correct |
129 ms |
5368 KB |
Output is correct |
54 |
Correct |
133 ms |
5244 KB |
Output is correct |
55 |
Incorrect |
128 ms |
5200 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |