#include "minerals.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 43000;
int idx[MAX_N*2+1];
vector<pii> ans;
bool chk[MAX_N+1];
vector<int> vt1, vt2;
void solve(int x, int y){
/* printf("%d %d\n", x, y);
for(int i=x; i<=y; i++){
printf("%d ", idx[i]);
if(i==(x+y)/2){
printf("\n");
}
}
printf("\n");*/
if(y==x+1){
ans.pb({idx[x], idx[y]});
if(chk[idx[x]]){
Query(idx[x]); Query(idx[y]);
}
return;
}
int l = (y-x+1)/2;
int m = l/2;
int i;
if(chk[idx[x]]){
int prv;
i = x+l-1;
while(m>0){
prv = Query(idx[i]);
i--; m--;
}
for(int j = y; j >= x+l; j--){
int now = Query(idx[j]);
if(now==prv){
Query(idx[j]);
vt1.push_back(idx[j]);
}else{
vt2.push_back(idx[j]);
}
}
}else{
int prv;
i = x;
while(m>0){
prv = Query(idx[i]);
chk[i] = true;
m--; i++;
}
i--;
for(int j=x+l; j<=y; j++){
int now = Query(idx[j]);
if(now==prv){
vt1.push_back(idx[j]);
}else{
Query(idx[j]);
vt2.push_back(idx[j]);
}
}
}
int i3 = i;
int i2 = 2*i - x +2;
i++;
while(i<x+l){
chk[i2] = false;
idx[i2] = idx[i];
i++; i2++;
}
i = i3+1;
while(!vt1.empty()){
chk[vt1.back()] = true;
idx[i] = vt1.back(); vt1.pop_back(); i++;
}
while(!vt2.empty()){
chk[vt2.back()] = false;
idx[i2] = vt2.back(); vt2.pop_back(); i2++;
}
solve(x, i3*2 - x + 1); solve(i3*2+1 - x + 1, y);
}
void Solve(int N) {
int prv = 0;
int i1 = 1, i2 = N+1;
for(int i=1; i<=N*2; i++){
int now = Query(i);
if(now==prv){
idx[i2++] = i;
}else{
idx[i1++] = i;
}
prv = now;
}
for(int i=1; i<=N*2; i++) Query(i);
solve(1, N*2);
for(int i=0; i<ans.size(); i++){
Answer(ans[i].first, ans[i].second);
}
}
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:122:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<ans.size(); i++){
~^~~~~~~~~~~
minerals.cpp: In function 'void solve(int, int)':
minerals.cpp:80:4: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(now==prv){
^~
minerals.cpp:62:4: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(now==prv){
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |