#include "minerals.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define ull unsigned ll
#define pq priority_queue
#define pb push_back
#define all(x) x.begin(), x.end()
#define deb(x) if(debug) cerr << #x << " = " << x << '\n';
#define deb2(x,y) if(debug) cerr << #x << " = " << x << ", " << #y << " = " << y << '\n';
constexpr int N = 1e5+7;
constexpr int debug = 0;
stack<int> totake;
bool chek[N];
int sq;
int prv = 0, nxt = 0;
int rem;
void ans(int x){
stack<int> re;
int tok = 0;
while(!totake.empty()){
tok = totake.top();
totake.pop();
nxt = Query(tok);
if(nxt == prv) break;
re.push(tok);
prv = nxt;
}
prv = nxt;
Answer(x, tok);
rem -= 2;
deb2(x, tok);
chek[x] = 1;
chek[tok] = 1;
nxt = prv = Query(x);
while(!re.empty()){
totake.push(re.top());
nxt = prv = Query(re.top());
re.pop();
}
}
void put(int x){
nxt = Query(x);
if(nxt == prv){
ans(x);
}
else{
totake.push(x);
}
prv = nxt;
}
void Solve(int n) {
rem = 2*n;
sq = sqrt(n)+1;
int siz = 0;
int ob = 1;
while(ob <= 2*n){
if(rem == 0) return;
while(prv < sq){
if(!chek[ob]) put(ob);
ob++;
if(ob > 2*n) break;
if(rem == 0) return;
}
for(int i = ob+1; i <= 2*n; i++){
if(chek[i]) continue;
if(prv == 0) break;
put(i);
if(rem == 0) return;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |