# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
485435 |
2021-11-07T18:23:23 Z |
blue |
Pilot (NOI19_pilot) |
C++17 |
|
987 ms |
52124 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using vi = vector<int>;
const int mx = 1'000'000;
vi H;
long long ans = 0;
vi parent(mx);
vi subtree(mx, 1);
int root(int u)
{
if(parent[u] == u) return u;
else
{
parent[u] = root(parent[u]);
return parent[u];
}
}
long long ch(long long v)
{
return v*(v+1)/2;
}
int N, Q;
void join(int u, int v)
{
if(v < 0 || N <= v) return;
if(!subtree[v]) return;
u = root(u);
v = root(v);
if(u == v) return;
if(subtree[u] < subtree[v]) swap(u, v);
ans += ch(subtree[u] + subtree[v]) - ch(subtree[u]) - ch(subtree[v]);
parent[v] = u;
subtree[u] += subtree[v];
}
int main()
{
cin >> N >> Q;
H = vi(N+Q);
vi I(N+Q);
for(int i = 0; i < N+Q; i++)
{
cin >> H[i];
I[i] = i;
}
for(int i = 0; i < N+Q; i++) I[i] = i;
sort(I.begin(), I.end(), [] (int p, int q)
{
if(H[p] != H[q]) return H[p] < H[q];
else return p < q;
});
for(int i = 0; i < N; i++)
{
parent[i] = i;
subtree[i] = 0;
}
vector<long long> res(Q);
for(int i:I)
{
if(i < N)
{
ans++;
subtree[i] = 1;
join(i, i-1);
join(i, i+1);
}
else
{
res[i-N] = ans;
}
}
for(int j = 0; j < Q; j++) cout << res[j] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8012 KB |
Output is correct |
2 |
Correct |
4 ms |
8116 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8128 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8136 KB |
Output is correct |
8 |
Correct |
3 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8012 KB |
Output is correct |
2 |
Correct |
4 ms |
8116 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8128 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8136 KB |
Output is correct |
8 |
Correct |
3 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
3 ms |
8132 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8132 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
15 |
Correct |
4 ms |
8012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8012 KB |
Output is correct |
2 |
Correct |
4 ms |
8116 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8128 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8136 KB |
Output is correct |
8 |
Correct |
3 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
3 ms |
8132 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8132 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
15 |
Correct |
4 ms |
8012 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8136 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8012 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8012 KB |
Output is correct |
2 |
Correct |
4 ms |
8116 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8128 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8136 KB |
Output is correct |
8 |
Correct |
3 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
3 ms |
8132 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8132 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
15 |
Correct |
4 ms |
8012 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8136 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8012 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
5 ms |
8140 KB |
Output is correct |
23 |
Correct |
4 ms |
8140 KB |
Output is correct |
24 |
Correct |
4 ms |
8140 KB |
Output is correct |
25 |
Correct |
4 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
9388 KB |
Output is correct |
2 |
Correct |
43 ms |
9520 KB |
Output is correct |
3 |
Correct |
38 ms |
9292 KB |
Output is correct |
4 |
Correct |
39 ms |
9320 KB |
Output is correct |
5 |
Correct |
42 ms |
9348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
12332 KB |
Output is correct |
2 |
Correct |
76 ms |
12392 KB |
Output is correct |
3 |
Correct |
77 ms |
12484 KB |
Output is correct |
4 |
Correct |
78 ms |
12484 KB |
Output is correct |
5 |
Correct |
81 ms |
12372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
12388 KB |
Output is correct |
2 |
Correct |
80 ms |
12516 KB |
Output is correct |
3 |
Correct |
81 ms |
12516 KB |
Output is correct |
4 |
Correct |
80 ms |
12484 KB |
Output is correct |
5 |
Correct |
83 ms |
12700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8012 KB |
Output is correct |
2 |
Correct |
4 ms |
8116 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8128 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8136 KB |
Output is correct |
8 |
Correct |
3 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
41 ms |
9388 KB |
Output is correct |
12 |
Correct |
43 ms |
9520 KB |
Output is correct |
13 |
Correct |
38 ms |
9292 KB |
Output is correct |
14 |
Correct |
39 ms |
9320 KB |
Output is correct |
15 |
Correct |
42 ms |
9348 KB |
Output is correct |
16 |
Correct |
37 ms |
9380 KB |
Output is correct |
17 |
Correct |
43 ms |
9540 KB |
Output is correct |
18 |
Correct |
42 ms |
9556 KB |
Output is correct |
19 |
Correct |
38 ms |
9360 KB |
Output is correct |
20 |
Correct |
44 ms |
9420 KB |
Output is correct |
21 |
Correct |
40 ms |
9372 KB |
Output is correct |
22 |
Correct |
40 ms |
9420 KB |
Output is correct |
23 |
Correct |
41 ms |
9404 KB |
Output is correct |
24 |
Correct |
40 ms |
9348 KB |
Output is correct |
25 |
Correct |
39 ms |
9376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8012 KB |
Output is correct |
2 |
Correct |
4 ms |
8116 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8128 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8136 KB |
Output is correct |
8 |
Correct |
3 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
3 ms |
8132 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8132 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
15 |
Correct |
4 ms |
8012 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8136 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8012 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
5 ms |
8140 KB |
Output is correct |
23 |
Correct |
4 ms |
8140 KB |
Output is correct |
24 |
Correct |
4 ms |
8140 KB |
Output is correct |
25 |
Correct |
4 ms |
8140 KB |
Output is correct |
26 |
Correct |
41 ms |
9388 KB |
Output is correct |
27 |
Correct |
43 ms |
9520 KB |
Output is correct |
28 |
Correct |
38 ms |
9292 KB |
Output is correct |
29 |
Correct |
39 ms |
9320 KB |
Output is correct |
30 |
Correct |
42 ms |
9348 KB |
Output is correct |
31 |
Correct |
77 ms |
12332 KB |
Output is correct |
32 |
Correct |
76 ms |
12392 KB |
Output is correct |
33 |
Correct |
77 ms |
12484 KB |
Output is correct |
34 |
Correct |
78 ms |
12484 KB |
Output is correct |
35 |
Correct |
81 ms |
12372 KB |
Output is correct |
36 |
Correct |
78 ms |
12388 KB |
Output is correct |
37 |
Correct |
80 ms |
12516 KB |
Output is correct |
38 |
Correct |
81 ms |
12516 KB |
Output is correct |
39 |
Correct |
80 ms |
12484 KB |
Output is correct |
40 |
Correct |
83 ms |
12700 KB |
Output is correct |
41 |
Correct |
37 ms |
9380 KB |
Output is correct |
42 |
Correct |
43 ms |
9540 KB |
Output is correct |
43 |
Correct |
42 ms |
9556 KB |
Output is correct |
44 |
Correct |
38 ms |
9360 KB |
Output is correct |
45 |
Correct |
44 ms |
9420 KB |
Output is correct |
46 |
Correct |
40 ms |
9372 KB |
Output is correct |
47 |
Correct |
40 ms |
9420 KB |
Output is correct |
48 |
Correct |
41 ms |
9404 KB |
Output is correct |
49 |
Correct |
40 ms |
9348 KB |
Output is correct |
50 |
Correct |
39 ms |
9376 KB |
Output is correct |
51 |
Correct |
83 ms |
12300 KB |
Output is correct |
52 |
Correct |
87 ms |
12188 KB |
Output is correct |
53 |
Correct |
84 ms |
12228 KB |
Output is correct |
54 |
Correct |
90 ms |
12164 KB |
Output is correct |
55 |
Correct |
85 ms |
12308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8012 KB |
Output is correct |
2 |
Correct |
4 ms |
8116 KB |
Output is correct |
3 |
Correct |
4 ms |
8012 KB |
Output is correct |
4 |
Correct |
4 ms |
8128 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
3 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
8136 KB |
Output is correct |
8 |
Correct |
3 ms |
8140 KB |
Output is correct |
9 |
Correct |
3 ms |
8012 KB |
Output is correct |
10 |
Correct |
4 ms |
8140 KB |
Output is correct |
11 |
Correct |
3 ms |
8132 KB |
Output is correct |
12 |
Correct |
3 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8132 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
15 |
Correct |
4 ms |
8012 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8136 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8012 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
5 ms |
8140 KB |
Output is correct |
23 |
Correct |
4 ms |
8140 KB |
Output is correct |
24 |
Correct |
4 ms |
8140 KB |
Output is correct |
25 |
Correct |
4 ms |
8140 KB |
Output is correct |
26 |
Correct |
41 ms |
9388 KB |
Output is correct |
27 |
Correct |
43 ms |
9520 KB |
Output is correct |
28 |
Correct |
38 ms |
9292 KB |
Output is correct |
29 |
Correct |
39 ms |
9320 KB |
Output is correct |
30 |
Correct |
42 ms |
9348 KB |
Output is correct |
31 |
Correct |
77 ms |
12332 KB |
Output is correct |
32 |
Correct |
76 ms |
12392 KB |
Output is correct |
33 |
Correct |
77 ms |
12484 KB |
Output is correct |
34 |
Correct |
78 ms |
12484 KB |
Output is correct |
35 |
Correct |
81 ms |
12372 KB |
Output is correct |
36 |
Correct |
78 ms |
12388 KB |
Output is correct |
37 |
Correct |
80 ms |
12516 KB |
Output is correct |
38 |
Correct |
81 ms |
12516 KB |
Output is correct |
39 |
Correct |
80 ms |
12484 KB |
Output is correct |
40 |
Correct |
83 ms |
12700 KB |
Output is correct |
41 |
Correct |
37 ms |
9380 KB |
Output is correct |
42 |
Correct |
43 ms |
9540 KB |
Output is correct |
43 |
Correct |
42 ms |
9556 KB |
Output is correct |
44 |
Correct |
38 ms |
9360 KB |
Output is correct |
45 |
Correct |
44 ms |
9420 KB |
Output is correct |
46 |
Correct |
40 ms |
9372 KB |
Output is correct |
47 |
Correct |
40 ms |
9420 KB |
Output is correct |
48 |
Correct |
41 ms |
9404 KB |
Output is correct |
49 |
Correct |
40 ms |
9348 KB |
Output is correct |
50 |
Correct |
39 ms |
9376 KB |
Output is correct |
51 |
Correct |
83 ms |
12300 KB |
Output is correct |
52 |
Correct |
87 ms |
12188 KB |
Output is correct |
53 |
Correct |
84 ms |
12228 KB |
Output is correct |
54 |
Correct |
90 ms |
12164 KB |
Output is correct |
55 |
Correct |
85 ms |
12308 KB |
Output is correct |
56 |
Correct |
987 ms |
51504 KB |
Output is correct |
57 |
Correct |
962 ms |
50428 KB |
Output is correct |
58 |
Correct |
897 ms |
48652 KB |
Output is correct |
59 |
Correct |
928 ms |
49476 KB |
Output is correct |
60 |
Correct |
971 ms |
52124 KB |
Output is correct |