# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
224226 |
2020-04-17T14:13:20 Z |
bortoz |
Pilot (NOI19_pilot) |
C++17 |
|
1000 ms |
60116 KB |
#pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define fi first
#define se second
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, Q;
cin >> N >> Q;
vector<pair<int, int>> H(N);
vector<int> Y(Q);
for (int i = 0; i < N; i++) {
cin >> H[i].fi;
H[i].se = i;
}
for (int i = 0; i < Q; i++) {
cin >> Y[i];
}
vector<bool> vis(N);
vector<int> par(N), left(N), right(N);
iota(par.begin(), par.end(), 0);
iota(left.begin(), left.end(), 0);
iota(right.begin(), right.end(), 1);
function<ll(int)> way = [&](int v) {
return 1ll * (right[v] - left[v]) * (right[v] - left[v] + 1) / 2;
};
function<int(int)> find = [&](int v) {
return v == par[v] ? v : (par[v] = find(par[v]));
};
function<ll(int, int)> merge = [&](int a, int b) {
a = find(a), b = find(b);
ll r = way(a) + way(b);
par[a] = b;
left[b] = left[a];
return way(b) - r;
};
ll sum = 0;
vector<pair<int, ll>> res;
sort(H.begin(), H.end());
for (auto [h, x] : H) {
vis[x] = true;
if (x > 0 && vis[x - 1]) {
sum += merge(x - 1, x);
}
if (x + 1 < N && vis[x + 1]) {
sum += merge(x, x + 1);
}
res.emplace_back(h, sum += 1);
}
for (int i : Y) {
auto it = upper_bound(res.begin(), res.end(), make_pair(i, (ll)1e18));
cout << (it == res.begin() ? 0ll : prev(it)->se) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
4628 KB |
Output is correct |
2 |
Correct |
34 ms |
4592 KB |
Output is correct |
3 |
Correct |
32 ms |
4504 KB |
Output is correct |
4 |
Correct |
31 ms |
4464 KB |
Output is correct |
5 |
Correct |
32 ms |
4464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
5324 KB |
Output is correct |
2 |
Correct |
66 ms |
5356 KB |
Output is correct |
3 |
Correct |
52 ms |
5228 KB |
Output is correct |
4 |
Correct |
55 ms |
5356 KB |
Output is correct |
5 |
Correct |
53 ms |
5180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
5232 KB |
Output is correct |
2 |
Correct |
60 ms |
5228 KB |
Output is correct |
3 |
Correct |
59 ms |
5228 KB |
Output is correct |
4 |
Correct |
60 ms |
5484 KB |
Output is correct |
5 |
Correct |
59 ms |
5356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
36 ms |
4628 KB |
Output is correct |
12 |
Correct |
34 ms |
4592 KB |
Output is correct |
13 |
Correct |
32 ms |
4504 KB |
Output is correct |
14 |
Correct |
31 ms |
4464 KB |
Output is correct |
15 |
Correct |
32 ms |
4464 KB |
Output is correct |
16 |
Correct |
31 ms |
4552 KB |
Output is correct |
17 |
Correct |
34 ms |
4600 KB |
Output is correct |
18 |
Correct |
34 ms |
4592 KB |
Output is correct |
19 |
Correct |
31 ms |
4472 KB |
Output is correct |
20 |
Correct |
35 ms |
4600 KB |
Output is correct |
21 |
Correct |
33 ms |
4464 KB |
Output is correct |
22 |
Correct |
33 ms |
4464 KB |
Output is correct |
23 |
Correct |
34 ms |
4592 KB |
Output is correct |
24 |
Correct |
31 ms |
4464 KB |
Output is correct |
25 |
Correct |
33 ms |
4592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
36 ms |
4628 KB |
Output is correct |
27 |
Correct |
34 ms |
4592 KB |
Output is correct |
28 |
Correct |
32 ms |
4504 KB |
Output is correct |
29 |
Correct |
31 ms |
4464 KB |
Output is correct |
30 |
Correct |
32 ms |
4464 KB |
Output is correct |
31 |
Correct |
68 ms |
5324 KB |
Output is correct |
32 |
Correct |
66 ms |
5356 KB |
Output is correct |
33 |
Correct |
52 ms |
5228 KB |
Output is correct |
34 |
Correct |
55 ms |
5356 KB |
Output is correct |
35 |
Correct |
53 ms |
5180 KB |
Output is correct |
36 |
Correct |
57 ms |
5232 KB |
Output is correct |
37 |
Correct |
60 ms |
5228 KB |
Output is correct |
38 |
Correct |
59 ms |
5228 KB |
Output is correct |
39 |
Correct |
60 ms |
5484 KB |
Output is correct |
40 |
Correct |
59 ms |
5356 KB |
Output is correct |
41 |
Correct |
31 ms |
4552 KB |
Output is correct |
42 |
Correct |
34 ms |
4600 KB |
Output is correct |
43 |
Correct |
34 ms |
4592 KB |
Output is correct |
44 |
Correct |
31 ms |
4472 KB |
Output is correct |
45 |
Correct |
35 ms |
4600 KB |
Output is correct |
46 |
Correct |
33 ms |
4464 KB |
Output is correct |
47 |
Correct |
33 ms |
4464 KB |
Output is correct |
48 |
Correct |
34 ms |
4592 KB |
Output is correct |
49 |
Correct |
31 ms |
4464 KB |
Output is correct |
50 |
Correct |
33 ms |
4592 KB |
Output is correct |
51 |
Correct |
63 ms |
5228 KB |
Output is correct |
52 |
Correct |
71 ms |
4976 KB |
Output is correct |
53 |
Correct |
62 ms |
5324 KB |
Output is correct |
54 |
Correct |
67 ms |
4968 KB |
Output is correct |
55 |
Correct |
61 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
36 ms |
4628 KB |
Output is correct |
27 |
Correct |
34 ms |
4592 KB |
Output is correct |
28 |
Correct |
32 ms |
4504 KB |
Output is correct |
29 |
Correct |
31 ms |
4464 KB |
Output is correct |
30 |
Correct |
32 ms |
4464 KB |
Output is correct |
31 |
Correct |
68 ms |
5324 KB |
Output is correct |
32 |
Correct |
66 ms |
5356 KB |
Output is correct |
33 |
Correct |
52 ms |
5228 KB |
Output is correct |
34 |
Correct |
55 ms |
5356 KB |
Output is correct |
35 |
Correct |
53 ms |
5180 KB |
Output is correct |
36 |
Correct |
57 ms |
5232 KB |
Output is correct |
37 |
Correct |
60 ms |
5228 KB |
Output is correct |
38 |
Correct |
59 ms |
5228 KB |
Output is correct |
39 |
Correct |
60 ms |
5484 KB |
Output is correct |
40 |
Correct |
59 ms |
5356 KB |
Output is correct |
41 |
Correct |
31 ms |
4552 KB |
Output is correct |
42 |
Correct |
34 ms |
4600 KB |
Output is correct |
43 |
Correct |
34 ms |
4592 KB |
Output is correct |
44 |
Correct |
31 ms |
4472 KB |
Output is correct |
45 |
Correct |
35 ms |
4600 KB |
Output is correct |
46 |
Correct |
33 ms |
4464 KB |
Output is correct |
47 |
Correct |
33 ms |
4464 KB |
Output is correct |
48 |
Correct |
34 ms |
4592 KB |
Output is correct |
49 |
Correct |
31 ms |
4464 KB |
Output is correct |
50 |
Correct |
33 ms |
4592 KB |
Output is correct |
51 |
Correct |
63 ms |
5228 KB |
Output is correct |
52 |
Correct |
71 ms |
4976 KB |
Output is correct |
53 |
Correct |
62 ms |
5324 KB |
Output is correct |
54 |
Correct |
67 ms |
4968 KB |
Output is correct |
55 |
Correct |
61 ms |
5228 KB |
Output is correct |
56 |
Correct |
950 ms |
45316 KB |
Output is correct |
57 |
Correct |
986 ms |
46272 KB |
Output is correct |
58 |
Correct |
923 ms |
55232 KB |
Output is correct |
59 |
Correct |
983 ms |
56980 KB |
Output is correct |
60 |
Execution timed out |
1010 ms |
60116 KB |
Time limit exceeded |