#include "Memory2_lib.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define cerr if(false) cerr
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
mt19937 rng(234256453);
int rn(int l, int r){
return uniform_int_distribution<int>(l,r)(rng);
}
void f(vector<int> &V, int val){
for(int i = 0; i < V.size(); ++i){
if(V[i] == val){
V.erase(V.begin() + i);
break;
}
}
}
void Solve(int t, int n){
vi v, u;
for(int i = 1; i <= n*2; ++i){
v.pb(i-1);
}
vector<vi> res(2*n);
while(v.size() + u.size() > 2){
if(v.size() <= 2){
for(int x: u) v.pb(x);
u.clear();
}
int m = v.size();
m--;
int x = u.size() ? u.back() : v[rn(0, m)]; if(u.size()) u.pop_back();
int y = v[rn(0, m)];
int z = v[rn(0, m)];
while(x==y) y=v[rn(0,m)];
while(x==z||y==z) z=v[rn(0,m)];
cerr << x << ' ' << y << ' ' << z << " wtf\n";
int X = Flip(x, y);
int Y = Flip(x, z);
int Z = Flip(y, z);
cerr << x << ' ' << y << ' ' << z << '\n';
cerr << X << ' ' << Y << ' ' << Z << '\n';
// cerr << '\n';
if(X == Y && Y == Z){
u.pb(x);
u.pb(y);
u.pb(z);
f(v, x);
f(v, y);
f(v, z);
// the unlucky case, small ones are equal so X=Y=Z
// we can either use a bigger one to find Z, or a number between them...
continue;
}
if(X == Y){
cerr << x << ' ' << X << '\n';
// cerr << "# " << v[x] << ' ' << X << '\n';
res[X].pb(x);
f(v, x);
}else if(X == Z){
cerr << y << ' ' << X << '\n';
// cerr << "# " << v[y] << ' ' << Y << '\n';
res[X].pb(y);
f(v, y);
}else{
cerr << z << ' ' << Z << '\n';
// cerr << "# " << v[z] << ' ' << Z << '\n';
res[Z].pb(z);
f(v, z);
}
cerr << v.size() << ' ' << u.size() << '\n';
}
for(int pos: v) res[n-1].pb(pos);
for(int i = 0; i < n; ++i){
// cerr << res[i][0] << ' ' << res[i][1] << ' ' << i << '\n';
Answer(res[i][0], res[i][1], i);
}
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... |