This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "grader.h"
//#include "grader.cpp"
#define f first
#define s second
#define pb push_back
#define vec vector
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef pair<int,int> pii;
typedef long double ld;
auto rng=bind(uniform_int_distribution<int>(1,1e9),mt19937(time(0)));
typedef long long ll;
const ll inf=1e18+100;
//const int N=49;
int query(vector<int> q);
int mx=0;
int tests=1000;
void solve(int n){
/// let's try
tests--;
vec<int>pr(n);iota(all(pr),1);
while(1){
int how=query(pr);
if(how==n) return;
if(how==0) break;
random_shuffle(all(pr));
}
vec<vec<pii>>w(n,vec<pii>());
auto del=[&](vec<int> &x,int v){
int j=find(all(x),v)-x.begin();
x.erase(x.begin()+j,x.begin()+j+1);
};
vec<int>badp,bad;
for(int i=1;i<=n;i++) bad.pb(i),badp.pb(i-1);
int pv=0;
while(1){
random_shuffle(all(badp));
int whatt=0;
for(int j=0;2*j+1<sz(badp);j++)swap(pr[badp[2*j]],pr[badp[2*j+1]]);
whatt=query(pr);
for(int j=0;2*j+1<sz(badp);j++)swap(pr[badp[2*j]],pr[badp[2*j+1]]);
if(whatt==pv) continue;
if(whatt==n) return;
int l=0,r=sz(badp)/2;
// debug()<<imie(sz(badp));
int mem=-1;
while(l!=r){
int tm=(l+r)>>1;
for(int j=0;j<=tm;j++) swap(pr[badp[2*j]],pr[badp[2*j+1]]);
int x=query(pr);
if(x==n) return;
for(int j=0;j<=tm;j++) swap(pr[badp[2*j]],pr[badp[2*j+1]]);
if(x>pv) r=tm,mem=x;
else l=tm+1;
}
// if(r==sz(badp)/2){
// continue;
// }
int v=badp[2*l],u=badp[2*l+1];
swap(pr[v],pr[u]);
int x=mem;
if(x==pv+2){
del(badp,v);del(badp,u);
del(bad,pr[v]);del(bad,pr[u]);
}
else{
int yself=-1;
for(auto &z : badp)if(z!=v && z!=u){yself=z;break;}
swap(pr[v],pr[yself]);
int y=query(pr);
if(y==n) return;
swap(pr[v],pr[yself]);
if(y!=pv){
del(badp,u);del(bad,pr[u]);
}
else{
del(badp,v);del(bad,pr[v]);
}
}
pv=x;
// debug()<<imie(pr);
continue;
}
query(pr);
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... |