#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 43000
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();
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;
}
//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();
rep(i,terc,ran.izq.size()-1) {
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:100:5: note: in expansion of macro 'rep'
100 | rep(i,terc,ran.izq.size()-1) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |