#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define pll pair<lli,lli>
#define MAX 1000000
struct x {
vector<lli> izq;
vector<lli> der;
};
lli n,pas,a,cont;
vector<pll> parejas;
queue<x> rangos;
lli vis[MAX+2];
void Solve(int N) {
n = N;
x ran;
//inicializo las mitades izq y der
pas = 0;
rep(i,1,2*n) {
a = Query(i);
if (a > pas) ran.izq.push_back(i);
else ran.der.push_back(i);
pas = a;
}
rep(i,1,2*n) Query(i);
//mientras exista que dividir, voy y a terminarme la cola y meterlo en mis resultados
rangos.push(ran);
while (!rangos.empty()) {
ran = rangos.front();
rangos.pop();
//debug(ran.izq.size());
//for(auto act : ran.izq) debugsl(act);
//cout << endl;
//for(auto act : ran.der) debugsl(act);
//cout << endl;
if (ran.izq.size() == 1) {
parejas.push_back({ran.izq[0], ran.der[0]});
continue;
}
if(ran.izq.size() == 2) {
Query(ran.izq[0]);
a = Query(ran.der[0]);
if (a == 2) {
parejas.push_back({ran.izq[0], ran.der[1]});
parejas.push_back({ran.izq[1], ran.der[0]});
}
else {
parejas.push_back({ran.izq[0], ran.der[0]});
parejas.push_back({ran.izq[1], ran.der[1]});
}
Query(ran.izq[0]);
Query(ran.der[0]);
continue;
}
lli terc = (ran.izq.size())/3;
if (ran.izq.size()%3 == 2) terc++;
x r1,r2,r3;
rep(i,0,terc-1) {
a = Query(ran.izq[i]);
r1.izq.push_back(ran.izq[i]);
}
pas = a;
for(auto act : ran.der) {
vis[act] = 0;
a = Query(act);
if(a == pas) {
Query(act);
r1.der.push_back(act);
vis[act] = 1;
}
pas = a;
}
//correct0
//ahora me toca llenar los r2 y r3
rep(i,0,terc-1) Query(ran.izq[i]);
cont = 1;
for(auto act : ran.der) {
if(vis[act] == 1) continue;
if (cont > terc) r3.der.push_back(act);
else {
r2.der.push_back(act);
Query(act);
}
cont++;
}
pas = r3.der.size();
//debugsl(terc);
//debug(pas);
rep(i,terc,ran.izq.size()-1) {
a = Query(ran.izq[i]);
if(a == pas) r3.izq.push_back(ran.izq[i]);
else r2.izq.push_back(ran.izq[i]);
Query(ran.izq[i]);
}
for(auto act : r3.der) Query(act);
rangos.push(r1);
rangos.push(r2);
rangos.push(r3);
}
for (auto act : parejas) Answer(act.first,act.second);
return;
}
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
| ^
minerals.cpp:111:5: note: in expansion of macro 'rep'
111 | rep(i,terc,ran.izq.size()-1) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
3 ms |
848 KB |
Output is correct |
4 |
Correct |
6 ms |
1680 KB |
Output is correct |
5 |
Correct |
11 ms |
2152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
1680 KB |
Output is correct |
9 |
Correct |
11 ms |
2152 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
1840 KB |
Output is correct |
12 |
Correct |
14 ms |
2324 KB |
Output is correct |
13 |
Correct |
9 ms |
2324 KB |
Output is correct |
14 |
Correct |
12 ms |
2172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
1680 KB |
Output is correct |
9 |
Correct |
11 ms |
2152 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
1840 KB |
Output is correct |
12 |
Correct |
14 ms |
2324 KB |
Output is correct |
13 |
Correct |
9 ms |
2324 KB |
Output is correct |
14 |
Correct |
12 ms |
2172 KB |
Output is correct |
15 |
Incorrect |
16 ms |
3828 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
1680 KB |
Output is correct |
9 |
Correct |
11 ms |
2152 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
1840 KB |
Output is correct |
12 |
Correct |
14 ms |
2324 KB |
Output is correct |
13 |
Correct |
9 ms |
2324 KB |
Output is correct |
14 |
Correct |
12 ms |
2172 KB |
Output is correct |
15 |
Incorrect |
16 ms |
3828 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
1680 KB |
Output is correct |
9 |
Correct |
11 ms |
2152 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
1840 KB |
Output is correct |
12 |
Correct |
14 ms |
2324 KB |
Output is correct |
13 |
Correct |
9 ms |
2324 KB |
Output is correct |
14 |
Correct |
12 ms |
2172 KB |
Output is correct |
15 |
Incorrect |
16 ms |
3828 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
1680 KB |
Output is correct |
9 |
Correct |
11 ms |
2152 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
1840 KB |
Output is correct |
12 |
Correct |
14 ms |
2324 KB |
Output is correct |
13 |
Correct |
9 ms |
2324 KB |
Output is correct |
14 |
Correct |
12 ms |
2172 KB |
Output is correct |
15 |
Incorrect |
16 ms |
3828 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
1680 KB |
Output is correct |
9 |
Correct |
11 ms |
2152 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
1840 KB |
Output is correct |
12 |
Correct |
14 ms |
2324 KB |
Output is correct |
13 |
Correct |
9 ms |
2324 KB |
Output is correct |
14 |
Correct |
12 ms |
2172 KB |
Output is correct |
15 |
Incorrect |
16 ms |
3828 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
6 ms |
1680 KB |
Output is correct |
9 |
Correct |
11 ms |
2152 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
1840 KB |
Output is correct |
12 |
Correct |
14 ms |
2324 KB |
Output is correct |
13 |
Correct |
9 ms |
2324 KB |
Output is correct |
14 |
Correct |
12 ms |
2172 KB |
Output is correct |
15 |
Incorrect |
16 ms |
3828 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |