# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
321153 |
2020-11-11T08:21:21 Z |
socho |
Pilot (NOI19_pilot) |
C++14 |
|
700 ms |
76584 KB |
#include "bits/stdc++.h"
using namespace std;
long long ans = 0;
const long long MXN = 1000005;
long long par[MXN], gs[MXN];
bool used[MXN];
void init() {
for (long long i=0; i<MXN; i++) par[i] = i;
}
long long parent(long long n) {
if (n == par[n]) return n;
return par[n] = parent(par[n]);
}
bool arc(long long a, long long b) {
return parent(a) == parent(b);
}
long long pa(long long n) {
return n * (n+1) / 2;
}
void connect(long long a, long long b) {
if (arc(a, b)) return;
long long ax = parent(a);
long long bx = parent(b);
long long oa = gs[ax];
long long ob = gs[bx];
ans -= pa(oa);
ans -= pa(ob);
ans += pa(oa+ob);
gs[ax] += gs[bx];
par[bx] = ax;
}
void prop(long long n) {
if (used[n-1] && used[n]) {
connect(n-1, n);
}
if (used[n] && used[n+1]) {
connect(n, n+1);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
long long n, q;
cin >> n >> q;
vector<pair<long long, long long> > ar(n);
for (long long i=0; i<n; i++) {
long long x;
cin >> x;
ar[i] = make_pair(x, i+1);
}
vector<pair<long long, long long> > qs;
for (long long i=0; i<q; i++) {
long long x;
cin >> x;
qs.push_back(make_pair(x, i));
}
memset(used, 0, sizeof used);
sort(ar.begin(), ar.end());
sort(qs.begin(), qs.end());
long long nxt = 0;
long long res[q];
init();
for (long long i=0; i<q; i++) {
long long qx = qs[i].first;
long long pos = qs[i].second;
while (nxt < n && ar[nxt].first <= qx) {
ans++;
used[ar[nxt].second] = true;
gs[ar[nxt].second] = 1;
prop(ar[nxt].second);
nxt++;
}
res[pos] = ans;
}
for (long long i=0; i<q; i++) cout << res[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9196 KB |
Output is correct |
2 |
Correct |
5 ms |
9196 KB |
Output is correct |
3 |
Correct |
6 ms |
9196 KB |
Output is correct |
4 |
Correct |
6 ms |
9216 KB |
Output is correct |
5 |
Correct |
6 ms |
9196 KB |
Output is correct |
6 |
Correct |
5 ms |
9196 KB |
Output is correct |
7 |
Correct |
6 ms |
9196 KB |
Output is correct |
8 |
Correct |
5 ms |
9196 KB |
Output is correct |
9 |
Correct |
5 ms |
9196 KB |
Output is correct |
10 |
Correct |
6 ms |
9196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9196 KB |
Output is correct |
2 |
Correct |
5 ms |
9196 KB |
Output is correct |
3 |
Correct |
6 ms |
9196 KB |
Output is correct |
4 |
Correct |
6 ms |
9216 KB |
Output is correct |
5 |
Correct |
6 ms |
9196 KB |
Output is correct |
6 |
Correct |
5 ms |
9196 KB |
Output is correct |
7 |
Correct |
6 ms |
9196 KB |
Output is correct |
8 |
Correct |
5 ms |
9196 KB |
Output is correct |
9 |
Correct |
5 ms |
9196 KB |
Output is correct |
10 |
Correct |
6 ms |
9196 KB |
Output is correct |
11 |
Correct |
5 ms |
9196 KB |
Output is correct |
12 |
Correct |
5 ms |
9196 KB |
Output is correct |
13 |
Correct |
6 ms |
9216 KB |
Output is correct |
14 |
Correct |
6 ms |
9196 KB |
Output is correct |
15 |
Correct |
6 ms |
9196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9196 KB |
Output is correct |
2 |
Correct |
5 ms |
9196 KB |
Output is correct |
3 |
Correct |
6 ms |
9196 KB |
Output is correct |
4 |
Correct |
6 ms |
9216 KB |
Output is correct |
5 |
Correct |
6 ms |
9196 KB |
Output is correct |
6 |
Correct |
5 ms |
9196 KB |
Output is correct |
7 |
Correct |
6 ms |
9196 KB |
Output is correct |
8 |
Correct |
5 ms |
9196 KB |
Output is correct |
9 |
Correct |
5 ms |
9196 KB |
Output is correct |
10 |
Correct |
6 ms |
9196 KB |
Output is correct |
11 |
Correct |
5 ms |
9196 KB |
Output is correct |
12 |
Correct |
5 ms |
9196 KB |
Output is correct |
13 |
Correct |
6 ms |
9216 KB |
Output is correct |
14 |
Correct |
6 ms |
9196 KB |
Output is correct |
15 |
Correct |
6 ms |
9196 KB |
Output is correct |
16 |
Correct |
6 ms |
9196 KB |
Output is correct |
17 |
Correct |
6 ms |
9216 KB |
Output is correct |
18 |
Correct |
6 ms |
9196 KB |
Output is correct |
19 |
Correct |
6 ms |
9196 KB |
Output is correct |
20 |
Correct |
6 ms |
9196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9196 KB |
Output is correct |
2 |
Correct |
5 ms |
9196 KB |
Output is correct |
3 |
Correct |
6 ms |
9196 KB |
Output is correct |
4 |
Correct |
6 ms |
9216 KB |
Output is correct |
5 |
Correct |
6 ms |
9196 KB |
Output is correct |
6 |
Correct |
5 ms |
9196 KB |
Output is correct |
7 |
Correct |
6 ms |
9196 KB |
Output is correct |
8 |
Correct |
5 ms |
9196 KB |
Output is correct |
9 |
Correct |
5 ms |
9196 KB |
Output is correct |
10 |
Correct |
6 ms |
9196 KB |
Output is correct |
11 |
Correct |
5 ms |
9196 KB |
Output is correct |
12 |
Correct |
5 ms |
9196 KB |
Output is correct |
13 |
Correct |
6 ms |
9216 KB |
Output is correct |
14 |
Correct |
6 ms |
9196 KB |
Output is correct |
15 |
Correct |
6 ms |
9196 KB |
Output is correct |
16 |
Correct |
6 ms |
9196 KB |
Output is correct |
17 |
Correct |
6 ms |
9216 KB |
Output is correct |
18 |
Correct |
6 ms |
9196 KB |
Output is correct |
19 |
Correct |
6 ms |
9196 KB |
Output is correct |
20 |
Correct |
6 ms |
9196 KB |
Output is correct |
21 |
Correct |
7 ms |
9196 KB |
Output is correct |
22 |
Correct |
6 ms |
9196 KB |
Output is correct |
23 |
Correct |
7 ms |
9196 KB |
Output is correct |
24 |
Correct |
6 ms |
9216 KB |
Output is correct |
25 |
Correct |
6 ms |
9196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
12012 KB |
Output is correct |
2 |
Correct |
29 ms |
12132 KB |
Output is correct |
3 |
Correct |
29 ms |
11884 KB |
Output is correct |
4 |
Correct |
27 ms |
11884 KB |
Output is correct |
5 |
Correct |
28 ms |
11876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
15836 KB |
Output is correct |
2 |
Correct |
63 ms |
15836 KB |
Output is correct |
3 |
Correct |
50 ms |
15836 KB |
Output is correct |
4 |
Correct |
50 ms |
15964 KB |
Output is correct |
5 |
Correct |
50 ms |
15836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
15836 KB |
Output is correct |
2 |
Correct |
50 ms |
15964 KB |
Output is correct |
3 |
Correct |
53 ms |
16092 KB |
Output is correct |
4 |
Correct |
50 ms |
15964 KB |
Output is correct |
5 |
Correct |
52 ms |
16220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9196 KB |
Output is correct |
2 |
Correct |
5 ms |
9196 KB |
Output is correct |
3 |
Correct |
6 ms |
9196 KB |
Output is correct |
4 |
Correct |
6 ms |
9216 KB |
Output is correct |
5 |
Correct |
6 ms |
9196 KB |
Output is correct |
6 |
Correct |
5 ms |
9196 KB |
Output is correct |
7 |
Correct |
6 ms |
9196 KB |
Output is correct |
8 |
Correct |
5 ms |
9196 KB |
Output is correct |
9 |
Correct |
5 ms |
9196 KB |
Output is correct |
10 |
Correct |
6 ms |
9196 KB |
Output is correct |
11 |
Correct |
29 ms |
12012 KB |
Output is correct |
12 |
Correct |
29 ms |
12132 KB |
Output is correct |
13 |
Correct |
29 ms |
11884 KB |
Output is correct |
14 |
Correct |
27 ms |
11884 KB |
Output is correct |
15 |
Correct |
28 ms |
11876 KB |
Output is correct |
16 |
Correct |
26 ms |
11884 KB |
Output is correct |
17 |
Correct |
28 ms |
12140 KB |
Output is correct |
18 |
Correct |
25 ms |
12132 KB |
Output is correct |
19 |
Correct |
23 ms |
11876 KB |
Output is correct |
20 |
Correct |
26 ms |
12008 KB |
Output is correct |
21 |
Correct |
27 ms |
11876 KB |
Output is correct |
22 |
Correct |
28 ms |
11940 KB |
Output is correct |
23 |
Correct |
26 ms |
12004 KB |
Output is correct |
24 |
Correct |
25 ms |
11876 KB |
Output is correct |
25 |
Correct |
26 ms |
12004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9196 KB |
Output is correct |
2 |
Correct |
5 ms |
9196 KB |
Output is correct |
3 |
Correct |
6 ms |
9196 KB |
Output is correct |
4 |
Correct |
6 ms |
9216 KB |
Output is correct |
5 |
Correct |
6 ms |
9196 KB |
Output is correct |
6 |
Correct |
5 ms |
9196 KB |
Output is correct |
7 |
Correct |
6 ms |
9196 KB |
Output is correct |
8 |
Correct |
5 ms |
9196 KB |
Output is correct |
9 |
Correct |
5 ms |
9196 KB |
Output is correct |
10 |
Correct |
6 ms |
9196 KB |
Output is correct |
11 |
Correct |
5 ms |
9196 KB |
Output is correct |
12 |
Correct |
5 ms |
9196 KB |
Output is correct |
13 |
Correct |
6 ms |
9216 KB |
Output is correct |
14 |
Correct |
6 ms |
9196 KB |
Output is correct |
15 |
Correct |
6 ms |
9196 KB |
Output is correct |
16 |
Correct |
6 ms |
9196 KB |
Output is correct |
17 |
Correct |
6 ms |
9216 KB |
Output is correct |
18 |
Correct |
6 ms |
9196 KB |
Output is correct |
19 |
Correct |
6 ms |
9196 KB |
Output is correct |
20 |
Correct |
6 ms |
9196 KB |
Output is correct |
21 |
Correct |
7 ms |
9196 KB |
Output is correct |
22 |
Correct |
6 ms |
9196 KB |
Output is correct |
23 |
Correct |
7 ms |
9196 KB |
Output is correct |
24 |
Correct |
6 ms |
9216 KB |
Output is correct |
25 |
Correct |
6 ms |
9196 KB |
Output is correct |
26 |
Correct |
29 ms |
12012 KB |
Output is correct |
27 |
Correct |
29 ms |
12132 KB |
Output is correct |
28 |
Correct |
29 ms |
11884 KB |
Output is correct |
29 |
Correct |
27 ms |
11884 KB |
Output is correct |
30 |
Correct |
28 ms |
11876 KB |
Output is correct |
31 |
Correct |
53 ms |
15836 KB |
Output is correct |
32 |
Correct |
63 ms |
15836 KB |
Output is correct |
33 |
Correct |
50 ms |
15836 KB |
Output is correct |
34 |
Correct |
50 ms |
15964 KB |
Output is correct |
35 |
Correct |
50 ms |
15836 KB |
Output is correct |
36 |
Correct |
58 ms |
15836 KB |
Output is correct |
37 |
Correct |
50 ms |
15964 KB |
Output is correct |
38 |
Correct |
53 ms |
16092 KB |
Output is correct |
39 |
Correct |
50 ms |
15964 KB |
Output is correct |
40 |
Correct |
52 ms |
16220 KB |
Output is correct |
41 |
Correct |
26 ms |
11884 KB |
Output is correct |
42 |
Correct |
28 ms |
12140 KB |
Output is correct |
43 |
Correct |
25 ms |
12132 KB |
Output is correct |
44 |
Correct |
23 ms |
11876 KB |
Output is correct |
45 |
Correct |
26 ms |
12008 KB |
Output is correct |
46 |
Correct |
27 ms |
11876 KB |
Output is correct |
47 |
Correct |
28 ms |
11940 KB |
Output is correct |
48 |
Correct |
26 ms |
12004 KB |
Output is correct |
49 |
Correct |
25 ms |
11876 KB |
Output is correct |
50 |
Correct |
26 ms |
12004 KB |
Output is correct |
51 |
Correct |
61 ms |
15836 KB |
Output is correct |
52 |
Correct |
59 ms |
15708 KB |
Output is correct |
53 |
Correct |
60 ms |
15836 KB |
Output is correct |
54 |
Correct |
61 ms |
15836 KB |
Output is correct |
55 |
Correct |
61 ms |
15708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9196 KB |
Output is correct |
2 |
Correct |
5 ms |
9196 KB |
Output is correct |
3 |
Correct |
6 ms |
9196 KB |
Output is correct |
4 |
Correct |
6 ms |
9216 KB |
Output is correct |
5 |
Correct |
6 ms |
9196 KB |
Output is correct |
6 |
Correct |
5 ms |
9196 KB |
Output is correct |
7 |
Correct |
6 ms |
9196 KB |
Output is correct |
8 |
Correct |
5 ms |
9196 KB |
Output is correct |
9 |
Correct |
5 ms |
9196 KB |
Output is correct |
10 |
Correct |
6 ms |
9196 KB |
Output is correct |
11 |
Correct |
5 ms |
9196 KB |
Output is correct |
12 |
Correct |
5 ms |
9196 KB |
Output is correct |
13 |
Correct |
6 ms |
9216 KB |
Output is correct |
14 |
Correct |
6 ms |
9196 KB |
Output is correct |
15 |
Correct |
6 ms |
9196 KB |
Output is correct |
16 |
Correct |
6 ms |
9196 KB |
Output is correct |
17 |
Correct |
6 ms |
9216 KB |
Output is correct |
18 |
Correct |
6 ms |
9196 KB |
Output is correct |
19 |
Correct |
6 ms |
9196 KB |
Output is correct |
20 |
Correct |
6 ms |
9196 KB |
Output is correct |
21 |
Correct |
7 ms |
9196 KB |
Output is correct |
22 |
Correct |
6 ms |
9196 KB |
Output is correct |
23 |
Correct |
7 ms |
9196 KB |
Output is correct |
24 |
Correct |
6 ms |
9216 KB |
Output is correct |
25 |
Correct |
6 ms |
9196 KB |
Output is correct |
26 |
Correct |
29 ms |
12012 KB |
Output is correct |
27 |
Correct |
29 ms |
12132 KB |
Output is correct |
28 |
Correct |
29 ms |
11884 KB |
Output is correct |
29 |
Correct |
27 ms |
11884 KB |
Output is correct |
30 |
Correct |
28 ms |
11876 KB |
Output is correct |
31 |
Correct |
53 ms |
15836 KB |
Output is correct |
32 |
Correct |
63 ms |
15836 KB |
Output is correct |
33 |
Correct |
50 ms |
15836 KB |
Output is correct |
34 |
Correct |
50 ms |
15964 KB |
Output is correct |
35 |
Correct |
50 ms |
15836 KB |
Output is correct |
36 |
Correct |
58 ms |
15836 KB |
Output is correct |
37 |
Correct |
50 ms |
15964 KB |
Output is correct |
38 |
Correct |
53 ms |
16092 KB |
Output is correct |
39 |
Correct |
50 ms |
15964 KB |
Output is correct |
40 |
Correct |
52 ms |
16220 KB |
Output is correct |
41 |
Correct |
26 ms |
11884 KB |
Output is correct |
42 |
Correct |
28 ms |
12140 KB |
Output is correct |
43 |
Correct |
25 ms |
12132 KB |
Output is correct |
44 |
Correct |
23 ms |
11876 KB |
Output is correct |
45 |
Correct |
26 ms |
12008 KB |
Output is correct |
46 |
Correct |
27 ms |
11876 KB |
Output is correct |
47 |
Correct |
28 ms |
11940 KB |
Output is correct |
48 |
Correct |
26 ms |
12004 KB |
Output is correct |
49 |
Correct |
25 ms |
11876 KB |
Output is correct |
50 |
Correct |
26 ms |
12004 KB |
Output is correct |
51 |
Correct |
61 ms |
15836 KB |
Output is correct |
52 |
Correct |
59 ms |
15708 KB |
Output is correct |
53 |
Correct |
60 ms |
15836 KB |
Output is correct |
54 |
Correct |
61 ms |
15836 KB |
Output is correct |
55 |
Correct |
61 ms |
15708 KB |
Output is correct |
56 |
Correct |
691 ms |
75192 KB |
Output is correct |
57 |
Correct |
688 ms |
74696 KB |
Output is correct |
58 |
Correct |
661 ms |
71212 KB |
Output is correct |
59 |
Correct |
657 ms |
72604 KB |
Output is correct |
60 |
Correct |
700 ms |
76584 KB |
Output is correct |