#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
#define MAXN 100100
vector<int> a, b;
int a1[MAXN];
vector<int> lo, hi, lo2, hi2;
int blo[MAXN], bhi[MAXN];
int mid, qq, q2;
void Solve(int n)
{
for (int i = 0; i < 2 * n; i++) {
a1[i] = Query(i + 1);
if (!i || a1[i] != a1[i - 1])
a.pb(i);
else
b.pb(i);
}
//for (int i = 0; i < 2 * n; i++) Query(i + 1);
for (int i = 0; i < n; i++) {
blo[i] = 0;
bhi[i] = n - 1;
}
lo.pb(0); hi.pb(n - 1);
while (1) {
if (lo.size() == 1) {
mid = (lo[0] + hi[0]) / 2;
for (int i = mid + 1; i <= hi[0]; i++) {
qq = Query(a[i] + 1);//cout<<a[i]+1<<'.'<<qq<<endl;
}
}
else {
for (int i = 0; i < lo.size(); i++) {
mid = (lo[i] + hi[i]) / 2;
if (i & 1) {
for (int j = lo[i]; j <= mid; j++)
qq = Query(a[j] + 1);
}
else {
for (int j = mid + 1; j <= hi[i]; j++)
qq = Query(a[j] + 1);
}
}
}
int ok = 0;
for (int i = 0; i < n; i++) {
mid = (blo[i] + bhi[i]) / 2;
q2 = Query(b[i] + 1);//cout<<b[i]+1<<','<<q2<<',';
if (qq == q2) {
bhi[i] = mid;
} else {
blo[i] = mid + 1;
}
//cout << blo[i]<<'.'<<bhi[i]<<' ';
if (blo[i] < bhi[i]) ok = 1;
qq = q2;
}//cout<<endl;
if (!ok) break;
lo2.clear(); hi2.clear();
for (int i = 0; i < lo.size(); i++) {
mid = (lo[i] + hi[i]) / 2;
lo2.pb(lo[i]);
lo2.pb(mid + 1);
hi2.pb(mid);
hi2.pb(hi[i]);
}
lo = lo2; hi = hi2;
}
for (int i = 0; i < n; i++) {
//cout<<b[i]+1<<' '<<a[blo[i]]+1<<endl;
Answer(b[i] + 1, a[blo[i]] + 1);
}
/*int v = Query(1);
for (int i = 1; i <= N; ++i) {
Answer(i, 2 * N + 1 - i);
}*/
}
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < lo.size(); i++) {
| ~~^~~~~~~~~~~
minerals.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < lo.size(); i++) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
768 KB |
Output is correct |
5 |
Correct |
11 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
15 |
Correct |
35 ms |
3188 KB |
Output is correct |
16 |
Correct |
31 ms |
3188 KB |
Output is correct |
17 |
Correct |
30 ms |
3316 KB |
Output is correct |
18 |
Correct |
30 ms |
3060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
15 |
Correct |
35 ms |
3188 KB |
Output is correct |
16 |
Correct |
31 ms |
3188 KB |
Output is correct |
17 |
Correct |
30 ms |
3316 KB |
Output is correct |
18 |
Correct |
30 ms |
3060 KB |
Output is correct |
19 |
Incorrect |
30 ms |
2932 KB |
Wrong Answer [2] |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
15 |
Correct |
35 ms |
3188 KB |
Output is correct |
16 |
Correct |
31 ms |
3188 KB |
Output is correct |
17 |
Correct |
30 ms |
3316 KB |
Output is correct |
18 |
Correct |
30 ms |
3060 KB |
Output is correct |
19 |
Incorrect |
30 ms |
2932 KB |
Wrong Answer [2] |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
15 |
Correct |
35 ms |
3188 KB |
Output is correct |
16 |
Correct |
31 ms |
3188 KB |
Output is correct |
17 |
Correct |
30 ms |
3316 KB |
Output is correct |
18 |
Correct |
30 ms |
3060 KB |
Output is correct |
19 |
Incorrect |
30 ms |
2932 KB |
Wrong Answer [2] |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
15 |
Correct |
35 ms |
3188 KB |
Output is correct |
16 |
Correct |
31 ms |
3188 KB |
Output is correct |
17 |
Correct |
30 ms |
3316 KB |
Output is correct |
18 |
Correct |
30 ms |
3060 KB |
Output is correct |
19 |
Incorrect |
30 ms |
2932 KB |
Wrong Answer [2] |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
15 |
Correct |
35 ms |
3188 KB |
Output is correct |
16 |
Correct |
31 ms |
3188 KB |
Output is correct |
17 |
Correct |
30 ms |
3316 KB |
Output is correct |
18 |
Correct |
30 ms |
3060 KB |
Output is correct |
19 |
Incorrect |
30 ms |
2932 KB |
Wrong Answer [2] |
20 |
Halted |
0 ms |
0 KB |
- |