# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
572438 |
2022-06-04T11:32:35 Z |
PiejanVDC |
Pilot (NOI19_pilot) |
C++17 |
|
1000 ms |
67688 KB |
#include <bits/stdc++.h>
using namespace std;
vector<int>par((int)1e6+5);
vector<long long>sz((int)1e6+5);
int UF(int u) {
if(par[u] == u) return u;
return par[u] = UF(par[u]);
}
signed main() {
int n,q; cin>>n>>q;
vector<int>v(n);
for(int i = 0 ; i < n ; i++)
par[i] = i, sz[i] = 1;
vector<vector<int>>p((int)1e6+1);
int X = 0;
for(auto &z : v) {
cin>>z;
p[z].push_back(X);
X++;
}
auto f = [&] (long long X) -> long long {
return (X * (X+1))/2;
};
vector<long long>Q((int)1e6+5);
long long ans = 0;
for(int i = 1 ; i <= (int)1e6 ; i++) {
for(auto z : p[i]) {
if(z != 0 && UF(z-1) != UF(z) && v[z-1] <= i) {
int A = UF(z-1), B = UF(z);
ans -= f(sz[A]);
ans += f(sz[A] + sz[B]);
par[B] = A;
sz[A] += sz[B];
sz[B] = 0;
} else ans++;
if(z != n-1 && UF(z) != UF(z+1) && v[z+1] < i) {
int A = UF(z), B = UF(z+1);
ans -= f(sz[A]) + f(sz[B]);
ans += f(sz[A] + sz[B]);
if(sz[A] < sz[B]) {
par[A] = B;
sz[B] += sz[A];
sz[A] = 0;
} else {
par[B] = A;
sz[A] += sz[B];
sz[B] = 0;
}
}
}
Q[i] = ans;
}
while(q--) {
int h; cin>>h;
cout << Q[h] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
43372 KB |
Output is correct |
2 |
Correct |
26 ms |
43256 KB |
Output is correct |
3 |
Correct |
24 ms |
43300 KB |
Output is correct |
4 |
Correct |
23 ms |
43348 KB |
Output is correct |
5 |
Correct |
23 ms |
43372 KB |
Output is correct |
6 |
Correct |
24 ms |
43372 KB |
Output is correct |
7 |
Correct |
23 ms |
43364 KB |
Output is correct |
8 |
Correct |
28 ms |
43348 KB |
Output is correct |
9 |
Correct |
26 ms |
43348 KB |
Output is correct |
10 |
Correct |
29 ms |
43340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
43372 KB |
Output is correct |
2 |
Correct |
26 ms |
43256 KB |
Output is correct |
3 |
Correct |
24 ms |
43300 KB |
Output is correct |
4 |
Correct |
23 ms |
43348 KB |
Output is correct |
5 |
Correct |
23 ms |
43372 KB |
Output is correct |
6 |
Correct |
24 ms |
43372 KB |
Output is correct |
7 |
Correct |
23 ms |
43364 KB |
Output is correct |
8 |
Correct |
28 ms |
43348 KB |
Output is correct |
9 |
Correct |
26 ms |
43348 KB |
Output is correct |
10 |
Correct |
29 ms |
43340 KB |
Output is correct |
11 |
Correct |
25 ms |
43340 KB |
Output is correct |
12 |
Correct |
24 ms |
43292 KB |
Output is correct |
13 |
Correct |
24 ms |
43300 KB |
Output is correct |
14 |
Correct |
27 ms |
43348 KB |
Output is correct |
15 |
Correct |
24 ms |
43284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
43372 KB |
Output is correct |
2 |
Correct |
26 ms |
43256 KB |
Output is correct |
3 |
Correct |
24 ms |
43300 KB |
Output is correct |
4 |
Correct |
23 ms |
43348 KB |
Output is correct |
5 |
Correct |
23 ms |
43372 KB |
Output is correct |
6 |
Correct |
24 ms |
43372 KB |
Output is correct |
7 |
Correct |
23 ms |
43364 KB |
Output is correct |
8 |
Correct |
28 ms |
43348 KB |
Output is correct |
9 |
Correct |
26 ms |
43348 KB |
Output is correct |
10 |
Correct |
29 ms |
43340 KB |
Output is correct |
11 |
Correct |
25 ms |
43340 KB |
Output is correct |
12 |
Correct |
24 ms |
43292 KB |
Output is correct |
13 |
Correct |
24 ms |
43300 KB |
Output is correct |
14 |
Correct |
27 ms |
43348 KB |
Output is correct |
15 |
Correct |
24 ms |
43284 KB |
Output is correct |
16 |
Correct |
24 ms |
43328 KB |
Output is correct |
17 |
Correct |
26 ms |
43348 KB |
Output is correct |
18 |
Correct |
24 ms |
43348 KB |
Output is correct |
19 |
Correct |
24 ms |
43348 KB |
Output is correct |
20 |
Correct |
25 ms |
43272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
43372 KB |
Output is correct |
2 |
Correct |
26 ms |
43256 KB |
Output is correct |
3 |
Correct |
24 ms |
43300 KB |
Output is correct |
4 |
Correct |
23 ms |
43348 KB |
Output is correct |
5 |
Correct |
23 ms |
43372 KB |
Output is correct |
6 |
Correct |
24 ms |
43372 KB |
Output is correct |
7 |
Correct |
23 ms |
43364 KB |
Output is correct |
8 |
Correct |
28 ms |
43348 KB |
Output is correct |
9 |
Correct |
26 ms |
43348 KB |
Output is correct |
10 |
Correct |
29 ms |
43340 KB |
Output is correct |
11 |
Correct |
25 ms |
43340 KB |
Output is correct |
12 |
Correct |
24 ms |
43292 KB |
Output is correct |
13 |
Correct |
24 ms |
43300 KB |
Output is correct |
14 |
Correct |
27 ms |
43348 KB |
Output is correct |
15 |
Correct |
24 ms |
43284 KB |
Output is correct |
16 |
Correct |
24 ms |
43328 KB |
Output is correct |
17 |
Correct |
26 ms |
43348 KB |
Output is correct |
18 |
Correct |
24 ms |
43348 KB |
Output is correct |
19 |
Correct |
24 ms |
43348 KB |
Output is correct |
20 |
Correct |
25 ms |
43272 KB |
Output is correct |
21 |
Correct |
32 ms |
43392 KB |
Output is correct |
22 |
Correct |
32 ms |
43348 KB |
Output is correct |
23 |
Correct |
26 ms |
43348 KB |
Output is correct |
24 |
Correct |
25 ms |
43416 KB |
Output is correct |
25 |
Correct |
25 ms |
43348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
45772 KB |
Output is correct |
2 |
Correct |
89 ms |
46844 KB |
Output is correct |
3 |
Correct |
71 ms |
45708 KB |
Output is correct |
4 |
Correct |
77 ms |
46616 KB |
Output is correct |
5 |
Correct |
63 ms |
45644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
47764 KB |
Output is correct |
2 |
Correct |
203 ms |
47784 KB |
Output is correct |
3 |
Correct |
210 ms |
47692 KB |
Output is correct |
4 |
Correct |
196 ms |
47856 KB |
Output is correct |
5 |
Correct |
218 ms |
47692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
47820 KB |
Output is correct |
2 |
Correct |
212 ms |
47660 KB |
Output is correct |
3 |
Correct |
213 ms |
47672 KB |
Output is correct |
4 |
Correct |
221 ms |
47892 KB |
Output is correct |
5 |
Correct |
246 ms |
47772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
43372 KB |
Output is correct |
2 |
Correct |
26 ms |
43256 KB |
Output is correct |
3 |
Correct |
24 ms |
43300 KB |
Output is correct |
4 |
Correct |
23 ms |
43348 KB |
Output is correct |
5 |
Correct |
23 ms |
43372 KB |
Output is correct |
6 |
Correct |
24 ms |
43372 KB |
Output is correct |
7 |
Correct |
23 ms |
43364 KB |
Output is correct |
8 |
Correct |
28 ms |
43348 KB |
Output is correct |
9 |
Correct |
26 ms |
43348 KB |
Output is correct |
10 |
Correct |
29 ms |
43340 KB |
Output is correct |
11 |
Correct |
66 ms |
45772 KB |
Output is correct |
12 |
Correct |
89 ms |
46844 KB |
Output is correct |
13 |
Correct |
71 ms |
45708 KB |
Output is correct |
14 |
Correct |
77 ms |
46616 KB |
Output is correct |
15 |
Correct |
63 ms |
45644 KB |
Output is correct |
16 |
Correct |
61 ms |
45652 KB |
Output is correct |
17 |
Correct |
82 ms |
46760 KB |
Output is correct |
18 |
Correct |
88 ms |
46792 KB |
Output is correct |
19 |
Correct |
74 ms |
45648 KB |
Output is correct |
20 |
Correct |
81 ms |
46752 KB |
Output is correct |
21 |
Correct |
64 ms |
45688 KB |
Output is correct |
22 |
Correct |
80 ms |
46636 KB |
Output is correct |
23 |
Correct |
72 ms |
45812 KB |
Output is correct |
24 |
Correct |
84 ms |
46608 KB |
Output is correct |
25 |
Correct |
69 ms |
45840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
43372 KB |
Output is correct |
2 |
Correct |
26 ms |
43256 KB |
Output is correct |
3 |
Correct |
24 ms |
43300 KB |
Output is correct |
4 |
Correct |
23 ms |
43348 KB |
Output is correct |
5 |
Correct |
23 ms |
43372 KB |
Output is correct |
6 |
Correct |
24 ms |
43372 KB |
Output is correct |
7 |
Correct |
23 ms |
43364 KB |
Output is correct |
8 |
Correct |
28 ms |
43348 KB |
Output is correct |
9 |
Correct |
26 ms |
43348 KB |
Output is correct |
10 |
Correct |
29 ms |
43340 KB |
Output is correct |
11 |
Correct |
25 ms |
43340 KB |
Output is correct |
12 |
Correct |
24 ms |
43292 KB |
Output is correct |
13 |
Correct |
24 ms |
43300 KB |
Output is correct |
14 |
Correct |
27 ms |
43348 KB |
Output is correct |
15 |
Correct |
24 ms |
43284 KB |
Output is correct |
16 |
Correct |
24 ms |
43328 KB |
Output is correct |
17 |
Correct |
26 ms |
43348 KB |
Output is correct |
18 |
Correct |
24 ms |
43348 KB |
Output is correct |
19 |
Correct |
24 ms |
43348 KB |
Output is correct |
20 |
Correct |
25 ms |
43272 KB |
Output is correct |
21 |
Correct |
32 ms |
43392 KB |
Output is correct |
22 |
Correct |
32 ms |
43348 KB |
Output is correct |
23 |
Correct |
26 ms |
43348 KB |
Output is correct |
24 |
Correct |
25 ms |
43416 KB |
Output is correct |
25 |
Correct |
25 ms |
43348 KB |
Output is correct |
26 |
Correct |
66 ms |
45772 KB |
Output is correct |
27 |
Correct |
89 ms |
46844 KB |
Output is correct |
28 |
Correct |
71 ms |
45708 KB |
Output is correct |
29 |
Correct |
77 ms |
46616 KB |
Output is correct |
30 |
Correct |
63 ms |
45644 KB |
Output is correct |
31 |
Correct |
208 ms |
47764 KB |
Output is correct |
32 |
Correct |
203 ms |
47784 KB |
Output is correct |
33 |
Correct |
210 ms |
47692 KB |
Output is correct |
34 |
Correct |
196 ms |
47856 KB |
Output is correct |
35 |
Correct |
218 ms |
47692 KB |
Output is correct |
36 |
Correct |
202 ms |
47820 KB |
Output is correct |
37 |
Correct |
212 ms |
47660 KB |
Output is correct |
38 |
Correct |
213 ms |
47672 KB |
Output is correct |
39 |
Correct |
221 ms |
47892 KB |
Output is correct |
40 |
Correct |
246 ms |
47772 KB |
Output is correct |
41 |
Correct |
61 ms |
45652 KB |
Output is correct |
42 |
Correct |
82 ms |
46760 KB |
Output is correct |
43 |
Correct |
88 ms |
46792 KB |
Output is correct |
44 |
Correct |
74 ms |
45648 KB |
Output is correct |
45 |
Correct |
81 ms |
46752 KB |
Output is correct |
46 |
Correct |
64 ms |
45688 KB |
Output is correct |
47 |
Correct |
80 ms |
46636 KB |
Output is correct |
48 |
Correct |
72 ms |
45812 KB |
Output is correct |
49 |
Correct |
84 ms |
46608 KB |
Output is correct |
50 |
Correct |
69 ms |
45840 KB |
Output is correct |
51 |
Correct |
213 ms |
46520 KB |
Output is correct |
52 |
Correct |
254 ms |
47184 KB |
Output is correct |
53 |
Correct |
220 ms |
46612 KB |
Output is correct |
54 |
Correct |
241 ms |
47232 KB |
Output is correct |
55 |
Correct |
214 ms |
46556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
43372 KB |
Output is correct |
2 |
Correct |
26 ms |
43256 KB |
Output is correct |
3 |
Correct |
24 ms |
43300 KB |
Output is correct |
4 |
Correct |
23 ms |
43348 KB |
Output is correct |
5 |
Correct |
23 ms |
43372 KB |
Output is correct |
6 |
Correct |
24 ms |
43372 KB |
Output is correct |
7 |
Correct |
23 ms |
43364 KB |
Output is correct |
8 |
Correct |
28 ms |
43348 KB |
Output is correct |
9 |
Correct |
26 ms |
43348 KB |
Output is correct |
10 |
Correct |
29 ms |
43340 KB |
Output is correct |
11 |
Correct |
25 ms |
43340 KB |
Output is correct |
12 |
Correct |
24 ms |
43292 KB |
Output is correct |
13 |
Correct |
24 ms |
43300 KB |
Output is correct |
14 |
Correct |
27 ms |
43348 KB |
Output is correct |
15 |
Correct |
24 ms |
43284 KB |
Output is correct |
16 |
Correct |
24 ms |
43328 KB |
Output is correct |
17 |
Correct |
26 ms |
43348 KB |
Output is correct |
18 |
Correct |
24 ms |
43348 KB |
Output is correct |
19 |
Correct |
24 ms |
43348 KB |
Output is correct |
20 |
Correct |
25 ms |
43272 KB |
Output is correct |
21 |
Correct |
32 ms |
43392 KB |
Output is correct |
22 |
Correct |
32 ms |
43348 KB |
Output is correct |
23 |
Correct |
26 ms |
43348 KB |
Output is correct |
24 |
Correct |
25 ms |
43416 KB |
Output is correct |
25 |
Correct |
25 ms |
43348 KB |
Output is correct |
26 |
Correct |
66 ms |
45772 KB |
Output is correct |
27 |
Correct |
89 ms |
46844 KB |
Output is correct |
28 |
Correct |
71 ms |
45708 KB |
Output is correct |
29 |
Correct |
77 ms |
46616 KB |
Output is correct |
30 |
Correct |
63 ms |
45644 KB |
Output is correct |
31 |
Correct |
208 ms |
47764 KB |
Output is correct |
32 |
Correct |
203 ms |
47784 KB |
Output is correct |
33 |
Correct |
210 ms |
47692 KB |
Output is correct |
34 |
Correct |
196 ms |
47856 KB |
Output is correct |
35 |
Correct |
218 ms |
47692 KB |
Output is correct |
36 |
Correct |
202 ms |
47820 KB |
Output is correct |
37 |
Correct |
212 ms |
47660 KB |
Output is correct |
38 |
Correct |
213 ms |
47672 KB |
Output is correct |
39 |
Correct |
221 ms |
47892 KB |
Output is correct |
40 |
Correct |
246 ms |
47772 KB |
Output is correct |
41 |
Correct |
61 ms |
45652 KB |
Output is correct |
42 |
Correct |
82 ms |
46760 KB |
Output is correct |
43 |
Correct |
88 ms |
46792 KB |
Output is correct |
44 |
Correct |
74 ms |
45648 KB |
Output is correct |
45 |
Correct |
81 ms |
46752 KB |
Output is correct |
46 |
Correct |
64 ms |
45688 KB |
Output is correct |
47 |
Correct |
80 ms |
46636 KB |
Output is correct |
48 |
Correct |
72 ms |
45812 KB |
Output is correct |
49 |
Correct |
84 ms |
46608 KB |
Output is correct |
50 |
Correct |
69 ms |
45840 KB |
Output is correct |
51 |
Correct |
213 ms |
46520 KB |
Output is correct |
52 |
Correct |
254 ms |
47184 KB |
Output is correct |
53 |
Correct |
220 ms |
46612 KB |
Output is correct |
54 |
Correct |
241 ms |
47232 KB |
Output is correct |
55 |
Correct |
214 ms |
46556 KB |
Output is correct |
56 |
Execution timed out |
1091 ms |
67688 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |