# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
478039 |
2021-10-05T09:21:32 Z |
aryan12 |
Pilot (NOI19_pilot) |
C++17 |
|
875 ms |
85476 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 5;
int par[N], siz[N];
bool cmp(array<int, 3> a, array<int, 3> b) {
if(a[0] == b[0]) {
return a[1] < b[1];
}
return a[0] < b[0];
}
int Find(int x) {
if(x == par[x]) {
return x;
}
return par[x] = Find(par[x]);
}
void Unite(int a, int b) {
a = Find(a), b = Find(b);
par[a] = b;
siz[b] += siz[a];
}
void Solve() {
for(int i = 0; i < N; i++) {
par[i] = i;
siz[i] = 1;
}
int n, q;
cin >> n >> q;
vector<int> input(n + 1);
vector<array<int, 3> > values;
for(int i = 1; i <= n; i++) {
cin >> input[i];
values.push_back({input[i], 0, i});
}
vector<int> query_ans(q + 1);
for(int i = 1; i <= q; i++) {
int cur_val;
cin >> cur_val;
values.push_back({cur_val, 1, i});
}
sort(values.begin(), values.end(), cmp);
int cur_ans = 0;
for(int i = 0; i < values.size(); i++) {
int val = values[i][0], in_or_query = values[i][1], idx = values[i][2];
if(in_or_query == 0) {
int before = Find(idx);
before = siz[before];
int before1 = Find(idx + 1);
before1 = siz[before1];
cur_ans -= (before * (before + 1)) / 2;
cur_ans -= (before1 * (before1 + 1)) / 2;
Unite(idx, idx + 1);
int after = Find(idx);
after = siz[after];
cur_ans += (after * (after + 1)) / 2;
}
else {
query_ans[idx] = cur_ans;
}
}
for(int i = 1; i <= q; i++) {
cout << query_ans[i] << "\n";
}
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
Compilation message
pilot.cpp: In function 'void Solve()':
pilot.cpp:51:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 0; i < values.size(); i++) {
| ~~^~~~~~~~~~~~~~~
pilot.cpp:52:7: warning: unused variable 'val' [-Wunused-variable]
52 | int val = values[i][0], in_or_query = values[i][1], idx = values[i][2];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15884 KB |
Output is correct |
3 |
Correct |
7 ms |
15904 KB |
Output is correct |
4 |
Correct |
8 ms |
15952 KB |
Output is correct |
5 |
Correct |
7 ms |
15880 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15928 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15884 KB |
Output is correct |
3 |
Correct |
7 ms |
15904 KB |
Output is correct |
4 |
Correct |
8 ms |
15952 KB |
Output is correct |
5 |
Correct |
7 ms |
15880 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15928 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15912 KB |
Output is correct |
11 |
Correct |
7 ms |
15912 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15948 KB |
Output is correct |
14 |
Correct |
10 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15884 KB |
Output is correct |
3 |
Correct |
7 ms |
15904 KB |
Output is correct |
4 |
Correct |
8 ms |
15952 KB |
Output is correct |
5 |
Correct |
7 ms |
15880 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15928 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15912 KB |
Output is correct |
11 |
Correct |
7 ms |
15912 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15948 KB |
Output is correct |
14 |
Correct |
10 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15944 KB |
Output is correct |
19 |
Correct |
8 ms |
15948 KB |
Output is correct |
20 |
Correct |
7 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15884 KB |
Output is correct |
3 |
Correct |
7 ms |
15904 KB |
Output is correct |
4 |
Correct |
8 ms |
15952 KB |
Output is correct |
5 |
Correct |
7 ms |
15880 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15928 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15912 KB |
Output is correct |
11 |
Correct |
7 ms |
15912 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15948 KB |
Output is correct |
14 |
Correct |
10 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15944 KB |
Output is correct |
19 |
Correct |
8 ms |
15948 KB |
Output is correct |
20 |
Correct |
7 ms |
15948 KB |
Output is correct |
21 |
Correct |
9 ms |
16076 KB |
Output is correct |
22 |
Correct |
11 ms |
16076 KB |
Output is correct |
23 |
Correct |
9 ms |
16076 KB |
Output is correct |
24 |
Correct |
9 ms |
16000 KB |
Output is correct |
25 |
Correct |
8 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
19932 KB |
Output is correct |
2 |
Correct |
41 ms |
19952 KB |
Output is correct |
3 |
Correct |
37 ms |
19844 KB |
Output is correct |
4 |
Correct |
37 ms |
19808 KB |
Output is correct |
5 |
Correct |
39 ms |
19904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
23476 KB |
Output is correct |
2 |
Correct |
75 ms |
23596 KB |
Output is correct |
3 |
Correct |
67 ms |
23592 KB |
Output is correct |
4 |
Correct |
68 ms |
23604 KB |
Output is correct |
5 |
Correct |
73 ms |
23560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
23580 KB |
Output is correct |
2 |
Correct |
72 ms |
23604 KB |
Output is correct |
3 |
Correct |
73 ms |
23540 KB |
Output is correct |
4 |
Correct |
67 ms |
23604 KB |
Output is correct |
5 |
Correct |
75 ms |
23572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15884 KB |
Output is correct |
3 |
Correct |
7 ms |
15904 KB |
Output is correct |
4 |
Correct |
8 ms |
15952 KB |
Output is correct |
5 |
Correct |
7 ms |
15880 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15928 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15912 KB |
Output is correct |
11 |
Correct |
38 ms |
19932 KB |
Output is correct |
12 |
Correct |
41 ms |
19952 KB |
Output is correct |
13 |
Correct |
37 ms |
19844 KB |
Output is correct |
14 |
Correct |
37 ms |
19808 KB |
Output is correct |
15 |
Correct |
39 ms |
19904 KB |
Output is correct |
16 |
Correct |
35 ms |
19836 KB |
Output is correct |
17 |
Correct |
44 ms |
20056 KB |
Output is correct |
18 |
Correct |
41 ms |
19904 KB |
Output is correct |
19 |
Correct |
39 ms |
19816 KB |
Output is correct |
20 |
Correct |
40 ms |
19856 KB |
Output is correct |
21 |
Correct |
37 ms |
19904 KB |
Output is correct |
22 |
Correct |
36 ms |
19904 KB |
Output is correct |
23 |
Correct |
37 ms |
19904 KB |
Output is correct |
24 |
Correct |
39 ms |
19904 KB |
Output is correct |
25 |
Correct |
39 ms |
19932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15884 KB |
Output is correct |
3 |
Correct |
7 ms |
15904 KB |
Output is correct |
4 |
Correct |
8 ms |
15952 KB |
Output is correct |
5 |
Correct |
7 ms |
15880 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15928 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15912 KB |
Output is correct |
11 |
Correct |
7 ms |
15912 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15948 KB |
Output is correct |
14 |
Correct |
10 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15944 KB |
Output is correct |
19 |
Correct |
8 ms |
15948 KB |
Output is correct |
20 |
Correct |
7 ms |
15948 KB |
Output is correct |
21 |
Correct |
9 ms |
16076 KB |
Output is correct |
22 |
Correct |
11 ms |
16076 KB |
Output is correct |
23 |
Correct |
9 ms |
16076 KB |
Output is correct |
24 |
Correct |
9 ms |
16000 KB |
Output is correct |
25 |
Correct |
8 ms |
16076 KB |
Output is correct |
26 |
Correct |
38 ms |
19932 KB |
Output is correct |
27 |
Correct |
41 ms |
19952 KB |
Output is correct |
28 |
Correct |
37 ms |
19844 KB |
Output is correct |
29 |
Correct |
37 ms |
19808 KB |
Output is correct |
30 |
Correct |
39 ms |
19904 KB |
Output is correct |
31 |
Correct |
76 ms |
23476 KB |
Output is correct |
32 |
Correct |
75 ms |
23596 KB |
Output is correct |
33 |
Correct |
67 ms |
23592 KB |
Output is correct |
34 |
Correct |
68 ms |
23604 KB |
Output is correct |
35 |
Correct |
73 ms |
23560 KB |
Output is correct |
36 |
Correct |
73 ms |
23580 KB |
Output is correct |
37 |
Correct |
72 ms |
23604 KB |
Output is correct |
38 |
Correct |
73 ms |
23540 KB |
Output is correct |
39 |
Correct |
67 ms |
23604 KB |
Output is correct |
40 |
Correct |
75 ms |
23572 KB |
Output is correct |
41 |
Correct |
35 ms |
19836 KB |
Output is correct |
42 |
Correct |
44 ms |
20056 KB |
Output is correct |
43 |
Correct |
41 ms |
19904 KB |
Output is correct |
44 |
Correct |
39 ms |
19816 KB |
Output is correct |
45 |
Correct |
40 ms |
19856 KB |
Output is correct |
46 |
Correct |
37 ms |
19904 KB |
Output is correct |
47 |
Correct |
36 ms |
19904 KB |
Output is correct |
48 |
Correct |
37 ms |
19904 KB |
Output is correct |
49 |
Correct |
39 ms |
19904 KB |
Output is correct |
50 |
Correct |
39 ms |
19932 KB |
Output is correct |
51 |
Correct |
80 ms |
23648 KB |
Output is correct |
52 |
Correct |
91 ms |
23560 KB |
Output is correct |
53 |
Correct |
81 ms |
23604 KB |
Output is correct |
54 |
Correct |
78 ms |
23612 KB |
Output is correct |
55 |
Correct |
76 ms |
23612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15884 KB |
Output is correct |
3 |
Correct |
7 ms |
15904 KB |
Output is correct |
4 |
Correct |
8 ms |
15952 KB |
Output is correct |
5 |
Correct |
7 ms |
15880 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15928 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15912 KB |
Output is correct |
11 |
Correct |
7 ms |
15912 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15948 KB |
Output is correct |
14 |
Correct |
10 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15944 KB |
Output is correct |
19 |
Correct |
8 ms |
15948 KB |
Output is correct |
20 |
Correct |
7 ms |
15948 KB |
Output is correct |
21 |
Correct |
9 ms |
16076 KB |
Output is correct |
22 |
Correct |
11 ms |
16076 KB |
Output is correct |
23 |
Correct |
9 ms |
16076 KB |
Output is correct |
24 |
Correct |
9 ms |
16000 KB |
Output is correct |
25 |
Correct |
8 ms |
16076 KB |
Output is correct |
26 |
Correct |
38 ms |
19932 KB |
Output is correct |
27 |
Correct |
41 ms |
19952 KB |
Output is correct |
28 |
Correct |
37 ms |
19844 KB |
Output is correct |
29 |
Correct |
37 ms |
19808 KB |
Output is correct |
30 |
Correct |
39 ms |
19904 KB |
Output is correct |
31 |
Correct |
76 ms |
23476 KB |
Output is correct |
32 |
Correct |
75 ms |
23596 KB |
Output is correct |
33 |
Correct |
67 ms |
23592 KB |
Output is correct |
34 |
Correct |
68 ms |
23604 KB |
Output is correct |
35 |
Correct |
73 ms |
23560 KB |
Output is correct |
36 |
Correct |
73 ms |
23580 KB |
Output is correct |
37 |
Correct |
72 ms |
23604 KB |
Output is correct |
38 |
Correct |
73 ms |
23540 KB |
Output is correct |
39 |
Correct |
67 ms |
23604 KB |
Output is correct |
40 |
Correct |
75 ms |
23572 KB |
Output is correct |
41 |
Correct |
35 ms |
19836 KB |
Output is correct |
42 |
Correct |
44 ms |
20056 KB |
Output is correct |
43 |
Correct |
41 ms |
19904 KB |
Output is correct |
44 |
Correct |
39 ms |
19816 KB |
Output is correct |
45 |
Correct |
40 ms |
19856 KB |
Output is correct |
46 |
Correct |
37 ms |
19904 KB |
Output is correct |
47 |
Correct |
36 ms |
19904 KB |
Output is correct |
48 |
Correct |
37 ms |
19904 KB |
Output is correct |
49 |
Correct |
39 ms |
19904 KB |
Output is correct |
50 |
Correct |
39 ms |
19932 KB |
Output is correct |
51 |
Correct |
80 ms |
23648 KB |
Output is correct |
52 |
Correct |
91 ms |
23560 KB |
Output is correct |
53 |
Correct |
81 ms |
23604 KB |
Output is correct |
54 |
Correct |
78 ms |
23612 KB |
Output is correct |
55 |
Correct |
76 ms |
23612 KB |
Output is correct |
56 |
Correct |
875 ms |
83916 KB |
Output is correct |
57 |
Correct |
827 ms |
83208 KB |
Output is correct |
58 |
Correct |
807 ms |
79624 KB |
Output is correct |
59 |
Correct |
803 ms |
81140 KB |
Output is correct |
60 |
Correct |
869 ms |
85476 KB |
Output is correct |