# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
674739 |
2022-12-26T05:50:38 Z |
QwertyPi |
Pilot (NOI19_pilot) |
C++14 |
|
551 ms |
83224 KB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
const int MAXN = 1e6 + 11;
using namespace std;
int rans = 0;
struct DSU{
int dsu[MAXN], sz[MAXN];
void __init(int n){
for(int i = 0; i <= n; i++){
dsu[i] = i, sz[i] = 1;
}
}
int f(int x){
return x == dsu[x] ? x : dsu[x] = f(dsu[x]);
}
int s(int x){
return sz[f(x)];
}
void g(int x, int y){
x = f(x), y = f(y);
if(x != y){
rans += sz[x] * sz[y];
dsu[x] = y; sz[y] += sz[x];
}
}
} dsu;
int h[MAXN], ans[MAXN];
int32_t main(){
cin.tie(0); cout.tie(0)->sync_with_stdio(false);
int n, q; cin >> n >> q;
for(int i = 0; i < n; i++){
cin >> h[i];
}
dsu.__init(n);
vector<pair<int, int>> Q, pos;
for(int i = 0; i < q; i++){
int y; cin >> y; Q.push_back({y, i});
}
sort(Q.begin(), Q.end());
for(int i = 0; i < n; i++){
pos.push_back({h[i], i});
}
sort(pos.begin(), pos.end()); int pid = 0;
for(auto i : Q){
while(pid < n && pos[pid].fi <= i.fi) dsu.g(pos[pid].se, pos[pid].se + 1), pid++;
ans[i.se] = rans;
}
for(int i = 0; i < q; i++){
cout << ans[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
5328 KB |
Output is correct |
2 |
Correct |
23 ms |
5456 KB |
Output is correct |
3 |
Correct |
22 ms |
5200 KB |
Output is correct |
4 |
Correct |
19 ms |
5208 KB |
Output is correct |
5 |
Correct |
19 ms |
5148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
8320 KB |
Output is correct |
2 |
Correct |
36 ms |
8528 KB |
Output is correct |
3 |
Correct |
35 ms |
8320 KB |
Output is correct |
4 |
Correct |
37 ms |
8588 KB |
Output is correct |
5 |
Correct |
37 ms |
8296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
8520 KB |
Output is correct |
2 |
Correct |
34 ms |
8548 KB |
Output is correct |
3 |
Correct |
35 ms |
8528 KB |
Output is correct |
4 |
Correct |
36 ms |
8692 KB |
Output is correct |
5 |
Correct |
38 ms |
8840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
20 ms |
5328 KB |
Output is correct |
12 |
Correct |
23 ms |
5456 KB |
Output is correct |
13 |
Correct |
22 ms |
5200 KB |
Output is correct |
14 |
Correct |
19 ms |
5208 KB |
Output is correct |
15 |
Correct |
19 ms |
5148 KB |
Output is correct |
16 |
Correct |
19 ms |
5200 KB |
Output is correct |
17 |
Correct |
18 ms |
5412 KB |
Output is correct |
18 |
Correct |
18 ms |
5460 KB |
Output is correct |
19 |
Correct |
17 ms |
5200 KB |
Output is correct |
20 |
Correct |
19 ms |
5456 KB |
Output is correct |
21 |
Correct |
21 ms |
5200 KB |
Output is correct |
22 |
Correct |
18 ms |
5328 KB |
Output is correct |
23 |
Correct |
19 ms |
5388 KB |
Output is correct |
24 |
Correct |
17 ms |
5240 KB |
Output is correct |
25 |
Correct |
19 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
20 ms |
5328 KB |
Output is correct |
27 |
Correct |
23 ms |
5456 KB |
Output is correct |
28 |
Correct |
22 ms |
5200 KB |
Output is correct |
29 |
Correct |
19 ms |
5208 KB |
Output is correct |
30 |
Correct |
19 ms |
5148 KB |
Output is correct |
31 |
Correct |
34 ms |
8320 KB |
Output is correct |
32 |
Correct |
36 ms |
8528 KB |
Output is correct |
33 |
Correct |
35 ms |
8320 KB |
Output is correct |
34 |
Correct |
37 ms |
8588 KB |
Output is correct |
35 |
Correct |
37 ms |
8296 KB |
Output is correct |
36 |
Correct |
35 ms |
8520 KB |
Output is correct |
37 |
Correct |
34 ms |
8548 KB |
Output is correct |
38 |
Correct |
35 ms |
8528 KB |
Output is correct |
39 |
Correct |
36 ms |
8692 KB |
Output is correct |
40 |
Correct |
38 ms |
8840 KB |
Output is correct |
41 |
Correct |
19 ms |
5200 KB |
Output is correct |
42 |
Correct |
18 ms |
5412 KB |
Output is correct |
43 |
Correct |
18 ms |
5460 KB |
Output is correct |
44 |
Correct |
17 ms |
5200 KB |
Output is correct |
45 |
Correct |
19 ms |
5456 KB |
Output is correct |
46 |
Correct |
21 ms |
5200 KB |
Output is correct |
47 |
Correct |
18 ms |
5328 KB |
Output is correct |
48 |
Correct |
19 ms |
5388 KB |
Output is correct |
49 |
Correct |
17 ms |
5240 KB |
Output is correct |
50 |
Correct |
19 ms |
5332 KB |
Output is correct |
51 |
Correct |
44 ms |
8392 KB |
Output is correct |
52 |
Correct |
43 ms |
8408 KB |
Output is correct |
53 |
Correct |
44 ms |
8408 KB |
Output is correct |
54 |
Correct |
43 ms |
8428 KB |
Output is correct |
55 |
Correct |
43 ms |
8560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
20 ms |
5328 KB |
Output is correct |
27 |
Correct |
23 ms |
5456 KB |
Output is correct |
28 |
Correct |
22 ms |
5200 KB |
Output is correct |
29 |
Correct |
19 ms |
5208 KB |
Output is correct |
30 |
Correct |
19 ms |
5148 KB |
Output is correct |
31 |
Correct |
34 ms |
8320 KB |
Output is correct |
32 |
Correct |
36 ms |
8528 KB |
Output is correct |
33 |
Correct |
35 ms |
8320 KB |
Output is correct |
34 |
Correct |
37 ms |
8588 KB |
Output is correct |
35 |
Correct |
37 ms |
8296 KB |
Output is correct |
36 |
Correct |
35 ms |
8520 KB |
Output is correct |
37 |
Correct |
34 ms |
8548 KB |
Output is correct |
38 |
Correct |
35 ms |
8528 KB |
Output is correct |
39 |
Correct |
36 ms |
8692 KB |
Output is correct |
40 |
Correct |
38 ms |
8840 KB |
Output is correct |
41 |
Correct |
19 ms |
5200 KB |
Output is correct |
42 |
Correct |
18 ms |
5412 KB |
Output is correct |
43 |
Correct |
18 ms |
5460 KB |
Output is correct |
44 |
Correct |
17 ms |
5200 KB |
Output is correct |
45 |
Correct |
19 ms |
5456 KB |
Output is correct |
46 |
Correct |
21 ms |
5200 KB |
Output is correct |
47 |
Correct |
18 ms |
5328 KB |
Output is correct |
48 |
Correct |
19 ms |
5388 KB |
Output is correct |
49 |
Correct |
17 ms |
5240 KB |
Output is correct |
50 |
Correct |
19 ms |
5332 KB |
Output is correct |
51 |
Correct |
44 ms |
8392 KB |
Output is correct |
52 |
Correct |
43 ms |
8408 KB |
Output is correct |
53 |
Correct |
44 ms |
8408 KB |
Output is correct |
54 |
Correct |
43 ms |
8428 KB |
Output is correct |
55 |
Correct |
43 ms |
8560 KB |
Output is correct |
56 |
Correct |
525 ms |
81016 KB |
Output is correct |
57 |
Correct |
531 ms |
81080 KB |
Output is correct |
58 |
Correct |
503 ms |
76268 KB |
Output is correct |
59 |
Correct |
528 ms |
78264 KB |
Output is correct |
60 |
Correct |
551 ms |
83224 KB |
Output is correct |