#include <bits/stdc++.h>
#include "minerals.h"
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
int n;
vector <int> a, b;
int cur = 0;
bool open[maxN];
ll cntt =0;
void parallel_bs(vector <int> &w, int l = 1, int r = n){
if (l == r){
Answer(w.back(), a[l]);
w.clear();
return;
}
int mid = (l + r) / 2;
int last = 0;
for (int i = l; i <= mid; ++i){
if (open[a[i]]){
open[a[i]] = 0;
last = Query(a[i]);
}
}
for (int i = mid + 1; i <= r; ++i){
if (!open[a[i]]){
open[a[i]] = 1;
last = Query(a[i]);
}
}
vector <int> left, right;
int _ = 0;
for (_ = 0; _ < w.size(); ++_){
int i = w[_];
int tem = Query(i);
++cntt;
open[i] ^= 1;
if (last == tem) left.pb(i);
else right.pb(i);
if (left.size() == r - mid || right.size() == mid - l + 1) break;
last = tem;
}
++_;
if (left.size() == r - mid){
for (; _ < w.size(); ++_){
int i = w[_];
right.pb(i);
}
}
else if (right.size() == mid - l + 1){
for (; _ < w.size(); ++_){
int i = w[_];
left.pb(i);
}
}
swap(left, right);
//cerr << l << " " << r << " " << mid << " " << left.size() << " " << right.size() << "\n";
assert(right.size() == r - mid);
w.clear();
parallel_bs(left, l, mid);
parallel_bs(right, mid + 1, r);
}
void Solve(int N){
n = N;
int last = 0;
a.pb(0);
for (int i = 1; i <= 2 * n; ++i){
int tem = Query(i);
if (tem > last) a.pb(i);
else b.pb(i);
last = tem;
}
fill (open, open + 2 * n + 1, 1);
parallel_bs(b, 1, n);
}
Compilation message
minerals.cpp: In function 'void parallel_bs(std::vector<int>&, int, int)':
minerals.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (_ = 0; _ < w.size(); ++_){
| ~~^~~~~~~~~~
minerals.cpp:66:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | if (left.size() == r - mid || right.size() == mid - l + 1) break;
| ~~~~~~~~~~~~^~~~~~~~~~
minerals.cpp:66:52: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | if (left.size() == r - mid || right.size() == mid - l + 1) break;
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~
minerals.cpp:70:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
70 | if (left.size() == r - mid){
| ~~~~~~~~~~~~^~~~~~~~~~
minerals.cpp:71:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (; _ < w.size(); ++_){
| ~~^~~~~~~~~~
minerals.cpp:76:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
76 | else if (right.size() == mid - l + 1){
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~
minerals.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (; _ < w.size(); ++_){
| ~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from minerals.cpp:1:
minerals.cpp:84:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
84 | assert(right.size() == r - mid);
| ~~~~~~~~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
464 KB |
Output is correct |
4 |
Correct |
6 ms |
636 KB |
Output is correct |
5 |
Correct |
12 ms |
1000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
464 KB |
Output is correct |
8 |
Correct |
6 ms |
636 KB |
Output is correct |
9 |
Correct |
12 ms |
1000 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
9 ms |
848 KB |
Output is correct |
12 |
Correct |
15 ms |
976 KB |
Output is correct |
13 |
Correct |
11 ms |
1068 KB |
Output is correct |
14 |
Correct |
9 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
464 KB |
Output is correct |
8 |
Correct |
6 ms |
636 KB |
Output is correct |
9 |
Correct |
12 ms |
1000 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
9 ms |
848 KB |
Output is correct |
12 |
Correct |
15 ms |
976 KB |
Output is correct |
13 |
Correct |
11 ms |
1068 KB |
Output is correct |
14 |
Correct |
9 ms |
984 KB |
Output is correct |
15 |
Correct |
34 ms |
2272 KB |
Output is correct |
16 |
Correct |
42 ms |
2308 KB |
Output is correct |
17 |
Correct |
23 ms |
2160 KB |
Output is correct |
18 |
Correct |
21 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
464 KB |
Output is correct |
8 |
Correct |
6 ms |
636 KB |
Output is correct |
9 |
Correct |
12 ms |
1000 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
9 ms |
848 KB |
Output is correct |
12 |
Correct |
15 ms |
976 KB |
Output is correct |
13 |
Correct |
11 ms |
1068 KB |
Output is correct |
14 |
Correct |
9 ms |
984 KB |
Output is correct |
15 |
Correct |
34 ms |
2272 KB |
Output is correct |
16 |
Correct |
42 ms |
2308 KB |
Output is correct |
17 |
Correct |
23 ms |
2160 KB |
Output is correct |
18 |
Correct |
21 ms |
2048 KB |
Output is correct |
19 |
Correct |
31 ms |
2288 KB |
Output is correct |
20 |
Correct |
38 ms |
2276 KB |
Output is correct |
21 |
Correct |
24 ms |
2176 KB |
Output is correct |
22 |
Correct |
26 ms |
2072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
464 KB |
Output is correct |
8 |
Correct |
6 ms |
636 KB |
Output is correct |
9 |
Correct |
12 ms |
1000 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
9 ms |
848 KB |
Output is correct |
12 |
Correct |
15 ms |
976 KB |
Output is correct |
13 |
Correct |
11 ms |
1068 KB |
Output is correct |
14 |
Correct |
9 ms |
984 KB |
Output is correct |
15 |
Correct |
34 ms |
2272 KB |
Output is correct |
16 |
Correct |
42 ms |
2308 KB |
Output is correct |
17 |
Correct |
23 ms |
2160 KB |
Output is correct |
18 |
Correct |
21 ms |
2048 KB |
Output is correct |
19 |
Correct |
31 ms |
2288 KB |
Output is correct |
20 |
Correct |
38 ms |
2276 KB |
Output is correct |
21 |
Correct |
24 ms |
2176 KB |
Output is correct |
22 |
Correct |
26 ms |
2072 KB |
Output is correct |
23 |
Correct |
38 ms |
2376 KB |
Output is correct |
24 |
Correct |
33 ms |
2416 KB |
Output is correct |
25 |
Correct |
27 ms |
2256 KB |
Output is correct |
26 |
Correct |
27 ms |
2120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
464 KB |
Output is correct |
8 |
Correct |
6 ms |
636 KB |
Output is correct |
9 |
Correct |
12 ms |
1000 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
9 ms |
848 KB |
Output is correct |
12 |
Correct |
15 ms |
976 KB |
Output is correct |
13 |
Correct |
11 ms |
1068 KB |
Output is correct |
14 |
Correct |
9 ms |
984 KB |
Output is correct |
15 |
Correct |
34 ms |
2272 KB |
Output is correct |
16 |
Correct |
42 ms |
2308 KB |
Output is correct |
17 |
Correct |
23 ms |
2160 KB |
Output is correct |
18 |
Correct |
21 ms |
2048 KB |
Output is correct |
19 |
Correct |
31 ms |
2288 KB |
Output is correct |
20 |
Correct |
38 ms |
2276 KB |
Output is correct |
21 |
Correct |
24 ms |
2176 KB |
Output is correct |
22 |
Correct |
26 ms |
2072 KB |
Output is correct |
23 |
Correct |
38 ms |
2376 KB |
Output is correct |
24 |
Correct |
33 ms |
2416 KB |
Output is correct |
25 |
Correct |
27 ms |
2256 KB |
Output is correct |
26 |
Correct |
27 ms |
2120 KB |
Output is correct |
27 |
Correct |
38 ms |
2436 KB |
Output is correct |
28 |
Correct |
35 ms |
2424 KB |
Output is correct |
29 |
Correct |
22 ms |
2404 KB |
Output is correct |
30 |
Correct |
22 ms |
2216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
464 KB |
Output is correct |
8 |
Correct |
6 ms |
636 KB |
Output is correct |
9 |
Correct |
12 ms |
1000 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
9 ms |
848 KB |
Output is correct |
12 |
Correct |
15 ms |
976 KB |
Output is correct |
13 |
Correct |
11 ms |
1068 KB |
Output is correct |
14 |
Correct |
9 ms |
984 KB |
Output is correct |
15 |
Correct |
34 ms |
2272 KB |
Output is correct |
16 |
Correct |
42 ms |
2308 KB |
Output is correct |
17 |
Correct |
23 ms |
2160 KB |
Output is correct |
18 |
Correct |
21 ms |
2048 KB |
Output is correct |
19 |
Correct |
31 ms |
2288 KB |
Output is correct |
20 |
Correct |
38 ms |
2276 KB |
Output is correct |
21 |
Correct |
24 ms |
2176 KB |
Output is correct |
22 |
Correct |
26 ms |
2072 KB |
Output is correct |
23 |
Correct |
38 ms |
2376 KB |
Output is correct |
24 |
Correct |
33 ms |
2416 KB |
Output is correct |
25 |
Correct |
27 ms |
2256 KB |
Output is correct |
26 |
Correct |
27 ms |
2120 KB |
Output is correct |
27 |
Correct |
38 ms |
2436 KB |
Output is correct |
28 |
Correct |
35 ms |
2424 KB |
Output is correct |
29 |
Correct |
22 ms |
2404 KB |
Output is correct |
30 |
Correct |
22 ms |
2216 KB |
Output is correct |
31 |
Correct |
33 ms |
2380 KB |
Output is correct |
32 |
Correct |
36 ms |
2492 KB |
Output is correct |
33 |
Correct |
28 ms |
2380 KB |
Output is correct |
34 |
Correct |
29 ms |
2264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
464 KB |
Output is correct |
8 |
Correct |
6 ms |
636 KB |
Output is correct |
9 |
Correct |
12 ms |
1000 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
9 ms |
848 KB |
Output is correct |
12 |
Correct |
15 ms |
976 KB |
Output is correct |
13 |
Correct |
11 ms |
1068 KB |
Output is correct |
14 |
Correct |
9 ms |
984 KB |
Output is correct |
15 |
Correct |
34 ms |
2272 KB |
Output is correct |
16 |
Correct |
42 ms |
2308 KB |
Output is correct |
17 |
Correct |
23 ms |
2160 KB |
Output is correct |
18 |
Correct |
21 ms |
2048 KB |
Output is correct |
19 |
Correct |
31 ms |
2288 KB |
Output is correct |
20 |
Correct |
38 ms |
2276 KB |
Output is correct |
21 |
Correct |
24 ms |
2176 KB |
Output is correct |
22 |
Correct |
26 ms |
2072 KB |
Output is correct |
23 |
Correct |
38 ms |
2376 KB |
Output is correct |
24 |
Correct |
33 ms |
2416 KB |
Output is correct |
25 |
Correct |
27 ms |
2256 KB |
Output is correct |
26 |
Correct |
27 ms |
2120 KB |
Output is correct |
27 |
Correct |
38 ms |
2436 KB |
Output is correct |
28 |
Correct |
35 ms |
2424 KB |
Output is correct |
29 |
Correct |
22 ms |
2404 KB |
Output is correct |
30 |
Correct |
22 ms |
2216 KB |
Output is correct |
31 |
Correct |
33 ms |
2380 KB |
Output is correct |
32 |
Correct |
36 ms |
2492 KB |
Output is correct |
33 |
Correct |
28 ms |
2380 KB |
Output is correct |
34 |
Correct |
29 ms |
2264 KB |
Output is correct |
35 |
Incorrect |
36 ms |
2500 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |