#include "minerals.h"
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;
vector<int> p;
vector<int> h1, h2;
int c = 0; // kolko z h1 je vnutri?
int lst = 0;
bool other(int x) // je druhy prvok typu x vnutri?
{
int now = Query(p[x]);
if (now != lst) return lst = now, false;
return lst = now, true;
}
void go(int c2)
{
while (c > c2) lst = Query(p[h1[--c]]);
while (c < c2) lst = Query(p[h1[c++]]);
}
void solve(int l, int r, vector<int> b)
{
if (l == r)
{
Answer(p[h1[l - 1]], p[b[0]]);
return;
}
int m = (l + r) / 2;
if (c > m) min(max(l, r - (1 * (r - l)) / 3), r - 1);
if (c < m) min(max(l, l + (1 * (r - l)) / 3), r - 1);
go(m);
vector<int> bl, br;
for (int i : b)
{
if (bl.size() == m - l + 1)
{
br.push_back(i);
}
else if (br.size() == r - m)
{
bl.push_back(i);
}
else
{
if (other(i)) bl.push_back(i);
else br.push_back(i);
}
}
solve(l, m, bl);
solve(m + 1, r, br);
}
int rnd()
{
return ((rand() % 10000) * 10000 + (rand() % 10000));
}
void Solve(int n)
{
for (int i = 0; i <= 2 * n; i++) p.push_back(i);
for (int i = 1; i <= 2 * n; i++) swap(p[i], p[1 + rnd() % i]);
for (int i = 1; i <= 2 * n; i++)
{
if (h1.size() == n || other(i)) h2.push_back(i);
else h1.push_back(i), c++;
}
solve(1, n, h2);
}
Compilation message
minerals.cpp: In function 'void solve(int, int, std::vector<int>)':
minerals.cpp:49:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if (bl.size() == m - l + 1)
| ~~~~~~~~~~^~~~~~~~~~~~
minerals.cpp:53:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | else if (br.size() == r - m)
| ~~~~~~~~~~^~~~~~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:76:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
76 | if (h1.size() == n || other(i)) h2.push_back(i);
| ~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
5 ms |
856 KB |
Output is correct |
5 |
Correct |
9 ms |
1248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1248 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1324 KB |
Output is correct |
13 |
Correct |
9 ms |
1368 KB |
Output is correct |
14 |
Correct |
9 ms |
1360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1248 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1324 KB |
Output is correct |
13 |
Correct |
9 ms |
1368 KB |
Output is correct |
14 |
Correct |
9 ms |
1360 KB |
Output is correct |
15 |
Correct |
27 ms |
2768 KB |
Output is correct |
16 |
Correct |
33 ms |
3016 KB |
Output is correct |
17 |
Correct |
26 ms |
2768 KB |
Output is correct |
18 |
Correct |
28 ms |
2692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1248 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1324 KB |
Output is correct |
13 |
Correct |
9 ms |
1368 KB |
Output is correct |
14 |
Correct |
9 ms |
1360 KB |
Output is correct |
15 |
Correct |
27 ms |
2768 KB |
Output is correct |
16 |
Correct |
33 ms |
3016 KB |
Output is correct |
17 |
Correct |
26 ms |
2768 KB |
Output is correct |
18 |
Correct |
28 ms |
2692 KB |
Output is correct |
19 |
Correct |
30 ms |
2768 KB |
Output is correct |
20 |
Correct |
29 ms |
2916 KB |
Output is correct |
21 |
Correct |
30 ms |
2768 KB |
Output is correct |
22 |
Correct |
30 ms |
2724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1248 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1324 KB |
Output is correct |
13 |
Correct |
9 ms |
1368 KB |
Output is correct |
14 |
Correct |
9 ms |
1360 KB |
Output is correct |
15 |
Correct |
27 ms |
2768 KB |
Output is correct |
16 |
Correct |
33 ms |
3016 KB |
Output is correct |
17 |
Correct |
26 ms |
2768 KB |
Output is correct |
18 |
Correct |
28 ms |
2692 KB |
Output is correct |
19 |
Correct |
30 ms |
2768 KB |
Output is correct |
20 |
Correct |
29 ms |
2916 KB |
Output is correct |
21 |
Correct |
30 ms |
2768 KB |
Output is correct |
22 |
Correct |
30 ms |
2724 KB |
Output is correct |
23 |
Correct |
28 ms |
3024 KB |
Output is correct |
24 |
Correct |
29 ms |
3024 KB |
Output is correct |
25 |
Correct |
33 ms |
3048 KB |
Output is correct |
26 |
Correct |
28 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1248 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1324 KB |
Output is correct |
13 |
Correct |
9 ms |
1368 KB |
Output is correct |
14 |
Correct |
9 ms |
1360 KB |
Output is correct |
15 |
Correct |
27 ms |
2768 KB |
Output is correct |
16 |
Correct |
33 ms |
3016 KB |
Output is correct |
17 |
Correct |
26 ms |
2768 KB |
Output is correct |
18 |
Correct |
28 ms |
2692 KB |
Output is correct |
19 |
Correct |
30 ms |
2768 KB |
Output is correct |
20 |
Correct |
29 ms |
2916 KB |
Output is correct |
21 |
Correct |
30 ms |
2768 KB |
Output is correct |
22 |
Correct |
30 ms |
2724 KB |
Output is correct |
23 |
Correct |
28 ms |
3024 KB |
Output is correct |
24 |
Correct |
29 ms |
3024 KB |
Output is correct |
25 |
Correct |
33 ms |
3048 KB |
Output is correct |
26 |
Correct |
28 ms |
2768 KB |
Output is correct |
27 |
Correct |
29 ms |
2928 KB |
Output is correct |
28 |
Correct |
36 ms |
3120 KB |
Output is correct |
29 |
Correct |
30 ms |
3024 KB |
Output is correct |
30 |
Correct |
30 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1248 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1324 KB |
Output is correct |
13 |
Correct |
9 ms |
1368 KB |
Output is correct |
14 |
Correct |
9 ms |
1360 KB |
Output is correct |
15 |
Correct |
27 ms |
2768 KB |
Output is correct |
16 |
Correct |
33 ms |
3016 KB |
Output is correct |
17 |
Correct |
26 ms |
2768 KB |
Output is correct |
18 |
Correct |
28 ms |
2692 KB |
Output is correct |
19 |
Correct |
30 ms |
2768 KB |
Output is correct |
20 |
Correct |
29 ms |
2916 KB |
Output is correct |
21 |
Correct |
30 ms |
2768 KB |
Output is correct |
22 |
Correct |
30 ms |
2724 KB |
Output is correct |
23 |
Correct |
28 ms |
3024 KB |
Output is correct |
24 |
Correct |
29 ms |
3024 KB |
Output is correct |
25 |
Correct |
33 ms |
3048 KB |
Output is correct |
26 |
Correct |
28 ms |
2768 KB |
Output is correct |
27 |
Correct |
29 ms |
2928 KB |
Output is correct |
28 |
Correct |
36 ms |
3120 KB |
Output is correct |
29 |
Correct |
30 ms |
3024 KB |
Output is correct |
30 |
Correct |
30 ms |
2768 KB |
Output is correct |
31 |
Incorrect |
34 ms |
3024 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1248 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1112 KB |
Output is correct |
12 |
Correct |
9 ms |
1324 KB |
Output is correct |
13 |
Correct |
9 ms |
1368 KB |
Output is correct |
14 |
Correct |
9 ms |
1360 KB |
Output is correct |
15 |
Correct |
27 ms |
2768 KB |
Output is correct |
16 |
Correct |
33 ms |
3016 KB |
Output is correct |
17 |
Correct |
26 ms |
2768 KB |
Output is correct |
18 |
Correct |
28 ms |
2692 KB |
Output is correct |
19 |
Correct |
30 ms |
2768 KB |
Output is correct |
20 |
Correct |
29 ms |
2916 KB |
Output is correct |
21 |
Correct |
30 ms |
2768 KB |
Output is correct |
22 |
Correct |
30 ms |
2724 KB |
Output is correct |
23 |
Correct |
28 ms |
3024 KB |
Output is correct |
24 |
Correct |
29 ms |
3024 KB |
Output is correct |
25 |
Correct |
33 ms |
3048 KB |
Output is correct |
26 |
Correct |
28 ms |
2768 KB |
Output is correct |
27 |
Correct |
29 ms |
2928 KB |
Output is correct |
28 |
Correct |
36 ms |
3120 KB |
Output is correct |
29 |
Correct |
30 ms |
3024 KB |
Output is correct |
30 |
Correct |
30 ms |
2768 KB |
Output is correct |
31 |
Incorrect |
34 ms |
3024 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |