# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
572410 |
2022-06-04T10:42:33 Z |
MODDI |
Pilot (NOI19_pilot) |
C++14 |
|
895 ms |
78452 KB |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
using namespace std;
const int maxn = 1e6 + 5;
ll parent[maxn];
ll sz[maxn];
bool on[maxn];
ll find(int x) {return x == parent[x]?x:parent[x] = find(parent[x]);}
ll rez = 0;
void mrg(int a, int b) {
a = find(a); b = find(b);
if (a == b) return;
rez -= sz[a] * (sz[a]+1) / 2;
rez -= sz[b] * (sz[b]+1) / 2;
sz[a] += sz[b];
rez += sz[a] * (sz[a]+1) / 2;
parent[b] = a;
}
vector<ll> G[maxn];
ll ans[maxn];
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
int n, q; cin>>n>>q;
for(int i = 0; i < n; i++){
parent[i] = i; sz[i] = 1;
}
for(int i = 0; i < n; i++){
int a;cin>>a;G[a].pb(i);
}
for(int i = 1; i <= 1000000; i++){
for(int x : G[i]){
++rez;
on[x] = 1;
if(x && on[x-1]) mrg(x, x-1);
if(x != n-1 && on[x+1]) mrg(x, x + 1);
}
ans[i] = rez;
}
for(int i = 0; i < q; i++){
int a; cin>>a;
cout<<ans[a]<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31620 KB |
Output is correct |
3 |
Correct |
17 ms |
31652 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31552 KB |
Output is correct |
6 |
Correct |
18 ms |
31604 KB |
Output is correct |
7 |
Correct |
17 ms |
31576 KB |
Output is correct |
8 |
Correct |
17 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31624 KB |
Output is correct |
10 |
Correct |
17 ms |
31584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31620 KB |
Output is correct |
3 |
Correct |
17 ms |
31652 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31552 KB |
Output is correct |
6 |
Correct |
18 ms |
31604 KB |
Output is correct |
7 |
Correct |
17 ms |
31576 KB |
Output is correct |
8 |
Correct |
17 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31624 KB |
Output is correct |
10 |
Correct |
17 ms |
31584 KB |
Output is correct |
11 |
Correct |
17 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31552 KB |
Output is correct |
13 |
Correct |
18 ms |
31644 KB |
Output is correct |
14 |
Correct |
22 ms |
31624 KB |
Output is correct |
15 |
Correct |
21 ms |
31628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31620 KB |
Output is correct |
3 |
Correct |
17 ms |
31652 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31552 KB |
Output is correct |
6 |
Correct |
18 ms |
31604 KB |
Output is correct |
7 |
Correct |
17 ms |
31576 KB |
Output is correct |
8 |
Correct |
17 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31624 KB |
Output is correct |
10 |
Correct |
17 ms |
31584 KB |
Output is correct |
11 |
Correct |
17 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31552 KB |
Output is correct |
13 |
Correct |
18 ms |
31644 KB |
Output is correct |
14 |
Correct |
22 ms |
31624 KB |
Output is correct |
15 |
Correct |
21 ms |
31628 KB |
Output is correct |
16 |
Correct |
18 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31660 KB |
Output is correct |
18 |
Correct |
18 ms |
31572 KB |
Output is correct |
19 |
Correct |
18 ms |
31544 KB |
Output is correct |
20 |
Correct |
20 ms |
31700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31620 KB |
Output is correct |
3 |
Correct |
17 ms |
31652 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31552 KB |
Output is correct |
6 |
Correct |
18 ms |
31604 KB |
Output is correct |
7 |
Correct |
17 ms |
31576 KB |
Output is correct |
8 |
Correct |
17 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31624 KB |
Output is correct |
10 |
Correct |
17 ms |
31584 KB |
Output is correct |
11 |
Correct |
17 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31552 KB |
Output is correct |
13 |
Correct |
18 ms |
31644 KB |
Output is correct |
14 |
Correct |
22 ms |
31624 KB |
Output is correct |
15 |
Correct |
21 ms |
31628 KB |
Output is correct |
16 |
Correct |
18 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31660 KB |
Output is correct |
18 |
Correct |
18 ms |
31572 KB |
Output is correct |
19 |
Correct |
18 ms |
31544 KB |
Output is correct |
20 |
Correct |
20 ms |
31700 KB |
Output is correct |
21 |
Correct |
22 ms |
31640 KB |
Output is correct |
22 |
Correct |
19 ms |
31640 KB |
Output is correct |
23 |
Correct |
19 ms |
31700 KB |
Output is correct |
24 |
Correct |
19 ms |
31700 KB |
Output is correct |
25 |
Correct |
17 ms |
31632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
35380 KB |
Output is correct |
2 |
Correct |
54 ms |
36404 KB |
Output is correct |
3 |
Correct |
44 ms |
35360 KB |
Output is correct |
4 |
Correct |
56 ms |
36164 KB |
Output is correct |
5 |
Correct |
43 ms |
35332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
37404 KB |
Output is correct |
2 |
Correct |
52 ms |
37368 KB |
Output is correct |
3 |
Correct |
51 ms |
37312 KB |
Output is correct |
4 |
Correct |
56 ms |
37576 KB |
Output is correct |
5 |
Correct |
62 ms |
37212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
37452 KB |
Output is correct |
2 |
Correct |
56 ms |
37292 KB |
Output is correct |
3 |
Correct |
58 ms |
37276 KB |
Output is correct |
4 |
Correct |
72 ms |
37652 KB |
Output is correct |
5 |
Correct |
75 ms |
37436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31620 KB |
Output is correct |
3 |
Correct |
17 ms |
31652 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31552 KB |
Output is correct |
6 |
Correct |
18 ms |
31604 KB |
Output is correct |
7 |
Correct |
17 ms |
31576 KB |
Output is correct |
8 |
Correct |
17 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31624 KB |
Output is correct |
10 |
Correct |
17 ms |
31584 KB |
Output is correct |
11 |
Correct |
38 ms |
35380 KB |
Output is correct |
12 |
Correct |
54 ms |
36404 KB |
Output is correct |
13 |
Correct |
44 ms |
35360 KB |
Output is correct |
14 |
Correct |
56 ms |
36164 KB |
Output is correct |
15 |
Correct |
43 ms |
35332 KB |
Output is correct |
16 |
Correct |
51 ms |
35324 KB |
Output is correct |
17 |
Correct |
64 ms |
36428 KB |
Output is correct |
18 |
Correct |
61 ms |
36460 KB |
Output is correct |
19 |
Correct |
48 ms |
35208 KB |
Output is correct |
20 |
Correct |
57 ms |
36360 KB |
Output is correct |
21 |
Correct |
43 ms |
35280 KB |
Output is correct |
22 |
Correct |
72 ms |
36332 KB |
Output is correct |
23 |
Correct |
50 ms |
35872 KB |
Output is correct |
24 |
Correct |
64 ms |
36344 KB |
Output is correct |
25 |
Correct |
59 ms |
35824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31620 KB |
Output is correct |
3 |
Correct |
17 ms |
31652 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31552 KB |
Output is correct |
6 |
Correct |
18 ms |
31604 KB |
Output is correct |
7 |
Correct |
17 ms |
31576 KB |
Output is correct |
8 |
Correct |
17 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31624 KB |
Output is correct |
10 |
Correct |
17 ms |
31584 KB |
Output is correct |
11 |
Correct |
17 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31552 KB |
Output is correct |
13 |
Correct |
18 ms |
31644 KB |
Output is correct |
14 |
Correct |
22 ms |
31624 KB |
Output is correct |
15 |
Correct |
21 ms |
31628 KB |
Output is correct |
16 |
Correct |
18 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31660 KB |
Output is correct |
18 |
Correct |
18 ms |
31572 KB |
Output is correct |
19 |
Correct |
18 ms |
31544 KB |
Output is correct |
20 |
Correct |
20 ms |
31700 KB |
Output is correct |
21 |
Correct |
22 ms |
31640 KB |
Output is correct |
22 |
Correct |
19 ms |
31640 KB |
Output is correct |
23 |
Correct |
19 ms |
31700 KB |
Output is correct |
24 |
Correct |
19 ms |
31700 KB |
Output is correct |
25 |
Correct |
17 ms |
31632 KB |
Output is correct |
26 |
Correct |
38 ms |
35380 KB |
Output is correct |
27 |
Correct |
54 ms |
36404 KB |
Output is correct |
28 |
Correct |
44 ms |
35360 KB |
Output is correct |
29 |
Correct |
56 ms |
36164 KB |
Output is correct |
30 |
Correct |
43 ms |
35332 KB |
Output is correct |
31 |
Correct |
64 ms |
37404 KB |
Output is correct |
32 |
Correct |
52 ms |
37368 KB |
Output is correct |
33 |
Correct |
51 ms |
37312 KB |
Output is correct |
34 |
Correct |
56 ms |
37576 KB |
Output is correct |
35 |
Correct |
62 ms |
37212 KB |
Output is correct |
36 |
Correct |
56 ms |
37452 KB |
Output is correct |
37 |
Correct |
56 ms |
37292 KB |
Output is correct |
38 |
Correct |
58 ms |
37276 KB |
Output is correct |
39 |
Correct |
72 ms |
37652 KB |
Output is correct |
40 |
Correct |
75 ms |
37436 KB |
Output is correct |
41 |
Correct |
51 ms |
35324 KB |
Output is correct |
42 |
Correct |
64 ms |
36428 KB |
Output is correct |
43 |
Correct |
61 ms |
36460 KB |
Output is correct |
44 |
Correct |
48 ms |
35208 KB |
Output is correct |
45 |
Correct |
57 ms |
36360 KB |
Output is correct |
46 |
Correct |
43 ms |
35280 KB |
Output is correct |
47 |
Correct |
72 ms |
36332 KB |
Output is correct |
48 |
Correct |
50 ms |
35872 KB |
Output is correct |
49 |
Correct |
64 ms |
36344 KB |
Output is correct |
50 |
Correct |
59 ms |
35824 KB |
Output is correct |
51 |
Correct |
88 ms |
37204 KB |
Output is correct |
52 |
Correct |
93 ms |
37884 KB |
Output is correct |
53 |
Correct |
80 ms |
37292 KB |
Output is correct |
54 |
Correct |
86 ms |
37916 KB |
Output is correct |
55 |
Correct |
71 ms |
37268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
16 ms |
31620 KB |
Output is correct |
3 |
Correct |
17 ms |
31652 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31552 KB |
Output is correct |
6 |
Correct |
18 ms |
31604 KB |
Output is correct |
7 |
Correct |
17 ms |
31576 KB |
Output is correct |
8 |
Correct |
17 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31624 KB |
Output is correct |
10 |
Correct |
17 ms |
31584 KB |
Output is correct |
11 |
Correct |
17 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31552 KB |
Output is correct |
13 |
Correct |
18 ms |
31644 KB |
Output is correct |
14 |
Correct |
22 ms |
31624 KB |
Output is correct |
15 |
Correct |
21 ms |
31628 KB |
Output is correct |
16 |
Correct |
18 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31660 KB |
Output is correct |
18 |
Correct |
18 ms |
31572 KB |
Output is correct |
19 |
Correct |
18 ms |
31544 KB |
Output is correct |
20 |
Correct |
20 ms |
31700 KB |
Output is correct |
21 |
Correct |
22 ms |
31640 KB |
Output is correct |
22 |
Correct |
19 ms |
31640 KB |
Output is correct |
23 |
Correct |
19 ms |
31700 KB |
Output is correct |
24 |
Correct |
19 ms |
31700 KB |
Output is correct |
25 |
Correct |
17 ms |
31632 KB |
Output is correct |
26 |
Correct |
38 ms |
35380 KB |
Output is correct |
27 |
Correct |
54 ms |
36404 KB |
Output is correct |
28 |
Correct |
44 ms |
35360 KB |
Output is correct |
29 |
Correct |
56 ms |
36164 KB |
Output is correct |
30 |
Correct |
43 ms |
35332 KB |
Output is correct |
31 |
Correct |
64 ms |
37404 KB |
Output is correct |
32 |
Correct |
52 ms |
37368 KB |
Output is correct |
33 |
Correct |
51 ms |
37312 KB |
Output is correct |
34 |
Correct |
56 ms |
37576 KB |
Output is correct |
35 |
Correct |
62 ms |
37212 KB |
Output is correct |
36 |
Correct |
56 ms |
37452 KB |
Output is correct |
37 |
Correct |
56 ms |
37292 KB |
Output is correct |
38 |
Correct |
58 ms |
37276 KB |
Output is correct |
39 |
Correct |
72 ms |
37652 KB |
Output is correct |
40 |
Correct |
75 ms |
37436 KB |
Output is correct |
41 |
Correct |
51 ms |
35324 KB |
Output is correct |
42 |
Correct |
64 ms |
36428 KB |
Output is correct |
43 |
Correct |
61 ms |
36460 KB |
Output is correct |
44 |
Correct |
48 ms |
35208 KB |
Output is correct |
45 |
Correct |
57 ms |
36360 KB |
Output is correct |
46 |
Correct |
43 ms |
35280 KB |
Output is correct |
47 |
Correct |
72 ms |
36332 KB |
Output is correct |
48 |
Correct |
50 ms |
35872 KB |
Output is correct |
49 |
Correct |
64 ms |
36344 KB |
Output is correct |
50 |
Correct |
59 ms |
35824 KB |
Output is correct |
51 |
Correct |
88 ms |
37204 KB |
Output is correct |
52 |
Correct |
93 ms |
37884 KB |
Output is correct |
53 |
Correct |
80 ms |
37292 KB |
Output is correct |
54 |
Correct |
86 ms |
37916 KB |
Output is correct |
55 |
Correct |
71 ms |
37268 KB |
Output is correct |
56 |
Correct |
834 ms |
78452 KB |
Output is correct |
57 |
Correct |
892 ms |
76780 KB |
Output is correct |
58 |
Correct |
798 ms |
74336 KB |
Output is correct |
59 |
Correct |
754 ms |
75772 KB |
Output is correct |
60 |
Correct |
895 ms |
78428 KB |
Output is correct |