# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
753114 |
2023-06-04T16:10:35 Z |
minhnhatnoe |
Pilot (NOI19_pilot) |
C++14 |
|
539 ms |
48344 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cpair(ll s){
return s * (s+1) / 2;
}
struct dsu{
ll c = 0;
vector<int> p;
vector<bool> s;
dsu(int n): p(n, -1), s(n) {}
int find(int v){
if (p[v] < 0) return v;
return p[v] = find(p[v]);
}
void merge(int a, int b){
a = find(a), b = find(b);
if (a == b) return;
if (-p[a] < -p[b]) swap(a, b);
c -= cpair(-p[a]) + cpair(-p[b]);
p[a] += p[b];
c += cpair(-p[a]);
p[b] = a;
}
void activate(int pos){
c += 1;
s[pos] = true;
if (pos && s[pos-1]){
merge(pos, pos-1);
}
if (pos != s.size()-1 && s[pos+1]){
merge(pos, pos+1);
}
}
};
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
dsu g(n);
vector<pair<int, int>> a(n), b(q);
for (int i=0; i<n; i++){
cin >> a[i].first;
a[i].second = i;
}
for (int i=0; i<q; i++){
cin >> b[i].first;
b[i].second = i;
}
vector<ll> result(q);
sort(a.begin(), a.end()), sort(b.begin(), b.end());
int aptr = 0;
for (int i=0; i<b.size(); i++){
while (aptr < a.size() && a[aptr].first <= b[i].first){
g.activate(a[aptr].second);
aptr++;
}
result[b[i].second] = g.c;
}
for (int i=0; i<result.size(); i++){
cout << result[i] << "\n";
}
}
Compilation message
pilot.cpp: In member function 'void dsu::activate(int)':
pilot.cpp:32:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if (pos != s.size()-1 && s[pos+1]){
| ~~~~^~~~~~~~~~~~~
pilot.cpp: In function 'int main()':
pilot.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i=0; i<b.size(); i++){
| ~^~~~~~~~~
pilot.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while (aptr < a.size() && a[aptr].first <= b[i].first){
| ~~~~~^~~~~~~~~~
pilot.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i=0; i<result.size(); i++){
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 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 |
19 ms |
1364 KB |
Output is correct |
2 |
Correct |
25 ms |
1492 KB |
Output is correct |
3 |
Correct |
18 ms |
1364 KB |
Output is correct |
4 |
Correct |
17 ms |
1396 KB |
Output is correct |
5 |
Correct |
19 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3768 KB |
Output is correct |
2 |
Correct |
33 ms |
3860 KB |
Output is correct |
3 |
Correct |
38 ms |
3792 KB |
Output is correct |
4 |
Correct |
42 ms |
3848 KB |
Output is correct |
5 |
Correct |
42 ms |
3788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3776 KB |
Output is correct |
2 |
Correct |
35 ms |
3796 KB |
Output is correct |
3 |
Correct |
37 ms |
3900 KB |
Output is correct |
4 |
Correct |
37 ms |
3788 KB |
Output is correct |
5 |
Correct |
35 ms |
3916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
19 ms |
1364 KB |
Output is correct |
12 |
Correct |
25 ms |
1492 KB |
Output is correct |
13 |
Correct |
18 ms |
1364 KB |
Output is correct |
14 |
Correct |
17 ms |
1396 KB |
Output is correct |
15 |
Correct |
19 ms |
1364 KB |
Output is correct |
16 |
Correct |
16 ms |
1364 KB |
Output is correct |
17 |
Correct |
16 ms |
1492 KB |
Output is correct |
18 |
Correct |
16 ms |
1492 KB |
Output is correct |
19 |
Correct |
16 ms |
1364 KB |
Output is correct |
20 |
Correct |
17 ms |
1364 KB |
Output is correct |
21 |
Correct |
20 ms |
1364 KB |
Output is correct |
22 |
Correct |
21 ms |
1428 KB |
Output is correct |
23 |
Correct |
17 ms |
1492 KB |
Output is correct |
24 |
Correct |
15 ms |
1420 KB |
Output is correct |
25 |
Correct |
17 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 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 |
19 ms |
1364 KB |
Output is correct |
27 |
Correct |
25 ms |
1492 KB |
Output is correct |
28 |
Correct |
18 ms |
1364 KB |
Output is correct |
29 |
Correct |
17 ms |
1396 KB |
Output is correct |
30 |
Correct |
19 ms |
1364 KB |
Output is correct |
31 |
Correct |
34 ms |
3768 KB |
Output is correct |
32 |
Correct |
33 ms |
3860 KB |
Output is correct |
33 |
Correct |
38 ms |
3792 KB |
Output is correct |
34 |
Correct |
42 ms |
3848 KB |
Output is correct |
35 |
Correct |
42 ms |
3788 KB |
Output is correct |
36 |
Correct |
37 ms |
3776 KB |
Output is correct |
37 |
Correct |
35 ms |
3796 KB |
Output is correct |
38 |
Correct |
37 ms |
3900 KB |
Output is correct |
39 |
Correct |
37 ms |
3788 KB |
Output is correct |
40 |
Correct |
35 ms |
3916 KB |
Output is correct |
41 |
Correct |
16 ms |
1364 KB |
Output is correct |
42 |
Correct |
16 ms |
1492 KB |
Output is correct |
43 |
Correct |
16 ms |
1492 KB |
Output is correct |
44 |
Correct |
16 ms |
1364 KB |
Output is correct |
45 |
Correct |
17 ms |
1364 KB |
Output is correct |
46 |
Correct |
20 ms |
1364 KB |
Output is correct |
47 |
Correct |
21 ms |
1428 KB |
Output is correct |
48 |
Correct |
17 ms |
1492 KB |
Output is correct |
49 |
Correct |
15 ms |
1420 KB |
Output is correct |
50 |
Correct |
17 ms |
1364 KB |
Output is correct |
51 |
Correct |
42 ms |
3740 KB |
Output is correct |
52 |
Correct |
45 ms |
3616 KB |
Output is correct |
53 |
Correct |
48 ms |
3772 KB |
Output is correct |
54 |
Correct |
41 ms |
3528 KB |
Output is correct |
55 |
Correct |
42 ms |
3640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 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 |
19 ms |
1364 KB |
Output is correct |
27 |
Correct |
25 ms |
1492 KB |
Output is correct |
28 |
Correct |
18 ms |
1364 KB |
Output is correct |
29 |
Correct |
17 ms |
1396 KB |
Output is correct |
30 |
Correct |
19 ms |
1364 KB |
Output is correct |
31 |
Correct |
34 ms |
3768 KB |
Output is correct |
32 |
Correct |
33 ms |
3860 KB |
Output is correct |
33 |
Correct |
38 ms |
3792 KB |
Output is correct |
34 |
Correct |
42 ms |
3848 KB |
Output is correct |
35 |
Correct |
42 ms |
3788 KB |
Output is correct |
36 |
Correct |
37 ms |
3776 KB |
Output is correct |
37 |
Correct |
35 ms |
3796 KB |
Output is correct |
38 |
Correct |
37 ms |
3900 KB |
Output is correct |
39 |
Correct |
37 ms |
3788 KB |
Output is correct |
40 |
Correct |
35 ms |
3916 KB |
Output is correct |
41 |
Correct |
16 ms |
1364 KB |
Output is correct |
42 |
Correct |
16 ms |
1492 KB |
Output is correct |
43 |
Correct |
16 ms |
1492 KB |
Output is correct |
44 |
Correct |
16 ms |
1364 KB |
Output is correct |
45 |
Correct |
17 ms |
1364 KB |
Output is correct |
46 |
Correct |
20 ms |
1364 KB |
Output is correct |
47 |
Correct |
21 ms |
1428 KB |
Output is correct |
48 |
Correct |
17 ms |
1492 KB |
Output is correct |
49 |
Correct |
15 ms |
1420 KB |
Output is correct |
50 |
Correct |
17 ms |
1364 KB |
Output is correct |
51 |
Correct |
42 ms |
3740 KB |
Output is correct |
52 |
Correct |
45 ms |
3616 KB |
Output is correct |
53 |
Correct |
48 ms |
3772 KB |
Output is correct |
54 |
Correct |
41 ms |
3528 KB |
Output is correct |
55 |
Correct |
42 ms |
3640 KB |
Output is correct |
56 |
Correct |
489 ms |
34484 KB |
Output is correct |
57 |
Correct |
492 ms |
46796 KB |
Output is correct |
58 |
Correct |
473 ms |
44512 KB |
Output is correct |
59 |
Correct |
456 ms |
45384 KB |
Output is correct |
60 |
Correct |
539 ms |
48344 KB |
Output is correct |