# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
371009 |
2021-02-25T14:29:16 Z |
wind_reaper |
Pilot (NOI19_pilot) |
C++17 |
|
707 ms |
52364 KB |
#include <bits/stdc++.h>
using namespace std;
struct dsu{
vector<int64_t> e;
vector<bool> active;
int64_t ans;
dsu(int n){
e.resize(n, -1);
ans = 0;
active.resize(n, 0);
}
int64_t get(int64_t x){
return (e[x] < 0 ? x : e[x] = get(e[x]));
}
int64_t f(int x){
int64_t t = -e[get(x)];
return (t*(t+1)) / 2;
}
bool unite(int x, int y){
x = get(x), y = get(y);
if(!active[x]){
ans += f(x);
active[x] = 1;
}
if(!active[y] || x == y)
return 0;
if(e[x] > e[y])
swap(x, y);
ans -= f(x) + f(y);
e[x] += e[y];
e[y] = x;
ans += f(x);
return 1;
}
};
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
vector<array<int, 2>> h(n), query(q);
for(int i = 0; i < n; i++){
cin >> h[i][0];
h[i][1] = i;
}
for(int i = 0; i < q; i++){
cin >> query[i][0];
query[i][1] = i;
}
sort(h.begin(), h.end());
sort(query.begin(), query.end());
vector<int64_t> ans(q);
dsu d(n);
int cur = 0;
for(int i = 0; i < q; i++){
while(cur < n && query[i][0] >= h[cur][0]){
int idx = h[cur][1];
int nxt = idx + 1;
int pre = idx - 1;
if(nxt < n) d.unite(idx, nxt);
if(pre >= 0) d.unite(idx, pre);
cur++;
}
ans[query[i][1]] = d.ans;
}
for(int i = 0; i < q; i++)
cout << ans[i] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
396 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
2412 KB |
Output is correct |
2 |
Correct |
30 ms |
2668 KB |
Output is correct |
3 |
Correct |
25 ms |
2412 KB |
Output is correct |
4 |
Correct |
23 ms |
2412 KB |
Output is correct |
5 |
Correct |
24 ms |
2412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
5356 KB |
Output is correct |
2 |
Correct |
47 ms |
5484 KB |
Output is correct |
3 |
Correct |
48 ms |
5484 KB |
Output is correct |
4 |
Correct |
47 ms |
5484 KB |
Output is correct |
5 |
Correct |
46 ms |
5356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
5484 KB |
Output is correct |
2 |
Correct |
53 ms |
5612 KB |
Output is correct |
3 |
Correct |
48 ms |
5612 KB |
Output is correct |
4 |
Correct |
49 ms |
5612 KB |
Output is correct |
5 |
Correct |
50 ms |
5740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
25 ms |
2412 KB |
Output is correct |
12 |
Correct |
30 ms |
2668 KB |
Output is correct |
13 |
Correct |
25 ms |
2412 KB |
Output is correct |
14 |
Correct |
23 ms |
2412 KB |
Output is correct |
15 |
Correct |
24 ms |
2412 KB |
Output is correct |
16 |
Correct |
22 ms |
2284 KB |
Output is correct |
17 |
Correct |
22 ms |
2540 KB |
Output is correct |
18 |
Correct |
24 ms |
2540 KB |
Output is correct |
19 |
Correct |
21 ms |
2412 KB |
Output is correct |
20 |
Correct |
23 ms |
2540 KB |
Output is correct |
21 |
Correct |
24 ms |
2284 KB |
Output is correct |
22 |
Correct |
21 ms |
2560 KB |
Output is correct |
23 |
Correct |
22 ms |
2540 KB |
Output is correct |
24 |
Correct |
20 ms |
2412 KB |
Output is correct |
25 |
Correct |
22 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
396 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
25 ms |
2412 KB |
Output is correct |
27 |
Correct |
30 ms |
2668 KB |
Output is correct |
28 |
Correct |
25 ms |
2412 KB |
Output is correct |
29 |
Correct |
23 ms |
2412 KB |
Output is correct |
30 |
Correct |
24 ms |
2412 KB |
Output is correct |
31 |
Correct |
46 ms |
5356 KB |
Output is correct |
32 |
Correct |
47 ms |
5484 KB |
Output is correct |
33 |
Correct |
48 ms |
5484 KB |
Output is correct |
34 |
Correct |
47 ms |
5484 KB |
Output is correct |
35 |
Correct |
46 ms |
5356 KB |
Output is correct |
36 |
Correct |
47 ms |
5484 KB |
Output is correct |
37 |
Correct |
53 ms |
5612 KB |
Output is correct |
38 |
Correct |
48 ms |
5612 KB |
Output is correct |
39 |
Correct |
49 ms |
5612 KB |
Output is correct |
40 |
Correct |
50 ms |
5740 KB |
Output is correct |
41 |
Correct |
22 ms |
2284 KB |
Output is correct |
42 |
Correct |
22 ms |
2540 KB |
Output is correct |
43 |
Correct |
24 ms |
2540 KB |
Output is correct |
44 |
Correct |
21 ms |
2412 KB |
Output is correct |
45 |
Correct |
23 ms |
2540 KB |
Output is correct |
46 |
Correct |
24 ms |
2284 KB |
Output is correct |
47 |
Correct |
21 ms |
2560 KB |
Output is correct |
48 |
Correct |
22 ms |
2540 KB |
Output is correct |
49 |
Correct |
20 ms |
2412 KB |
Output is correct |
50 |
Correct |
22 ms |
2432 KB |
Output is correct |
51 |
Correct |
57 ms |
5380 KB |
Output is correct |
52 |
Correct |
56 ms |
5228 KB |
Output is correct |
53 |
Correct |
57 ms |
5484 KB |
Output is correct |
54 |
Correct |
55 ms |
5228 KB |
Output is correct |
55 |
Correct |
57 ms |
5356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
396 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
25 ms |
2412 KB |
Output is correct |
27 |
Correct |
30 ms |
2668 KB |
Output is correct |
28 |
Correct |
25 ms |
2412 KB |
Output is correct |
29 |
Correct |
23 ms |
2412 KB |
Output is correct |
30 |
Correct |
24 ms |
2412 KB |
Output is correct |
31 |
Correct |
46 ms |
5356 KB |
Output is correct |
32 |
Correct |
47 ms |
5484 KB |
Output is correct |
33 |
Correct |
48 ms |
5484 KB |
Output is correct |
34 |
Correct |
47 ms |
5484 KB |
Output is correct |
35 |
Correct |
46 ms |
5356 KB |
Output is correct |
36 |
Correct |
47 ms |
5484 KB |
Output is correct |
37 |
Correct |
53 ms |
5612 KB |
Output is correct |
38 |
Correct |
48 ms |
5612 KB |
Output is correct |
39 |
Correct |
49 ms |
5612 KB |
Output is correct |
40 |
Correct |
50 ms |
5740 KB |
Output is correct |
41 |
Correct |
22 ms |
2284 KB |
Output is correct |
42 |
Correct |
22 ms |
2540 KB |
Output is correct |
43 |
Correct |
24 ms |
2540 KB |
Output is correct |
44 |
Correct |
21 ms |
2412 KB |
Output is correct |
45 |
Correct |
23 ms |
2540 KB |
Output is correct |
46 |
Correct |
24 ms |
2284 KB |
Output is correct |
47 |
Correct |
21 ms |
2560 KB |
Output is correct |
48 |
Correct |
22 ms |
2540 KB |
Output is correct |
49 |
Correct |
20 ms |
2412 KB |
Output is correct |
50 |
Correct |
22 ms |
2432 KB |
Output is correct |
51 |
Correct |
57 ms |
5380 KB |
Output is correct |
52 |
Correct |
56 ms |
5228 KB |
Output is correct |
53 |
Correct |
57 ms |
5484 KB |
Output is correct |
54 |
Correct |
55 ms |
5228 KB |
Output is correct |
55 |
Correct |
57 ms |
5356 KB |
Output is correct |
56 |
Correct |
693 ms |
51460 KB |
Output is correct |
57 |
Correct |
688 ms |
50540 KB |
Output is correct |
58 |
Correct |
655 ms |
48108 KB |
Output is correct |
59 |
Correct |
666 ms |
49132 KB |
Output is correct |
60 |
Correct |
707 ms |
52364 KB |
Output is correct |