Submission #336713

#TimeUsernameProblemLanguageResultExecution timeMemory
336713amoo_safarLibrary (JOI18_library)C++17
100 / 100
409 ms528 KiB
#include "library.h" #include <bits/stdc++.h> #define pb push_back #define all(x) x.begin(), x.end() using namespace std; vector< vector<int> > V; int n; int Ask(int L, int R){ vector<int> Q(n, 0); for(int i = L; i < R; i++) for(int j : V[i]) Q[j] = 1; // cerr << "#@$ "; // for(auto x : Q) cerr << x; // cerr << " -> " << Query(Q) << '\n'; return Query(Q); } bool Nei(int a, int b){ vector<int> Q(n, 0); Q[a] = 1; Q[b] = 1; return Query(Q) == 1; } int tri(int a, int b, int c){ vector<int> Q(n, 0); Q[a] = 1; Q[b] = 1; Q[c] = 1; return Query(Q); } void Insert(int i, int j){ assert(i < j); for(auto x : V[j]) V[i].pb(x); V[j].clear(); V.erase(V.begin() + j); } void Comb(int i, int j){ if(V[i].size() == 1) swap(V[i], V[j]); if(V[j].size() == 1){ if((V[i].size() == 1) || (Nei(V[j][0], V[i].back()))){ Insert(i, j); return ; } reverse(all(V[i])); assert(Nei(V[i].back(), V[j][0])); Insert(i, j); return ; } if(tri(V[i][0], V[j][0], V[j].back()) == 2 - (V[j].size() == 2)) reverse(all(V[i])); if(!Nei(V[i].back(), V[j][0])) reverse(all(V[j])); Insert(i, j); } void Solve(int _n){ n = _n; V.resize(n, vector<int>(0)); for(int i = 0; i < n; i++) V[i].pb(i); int L, R, mid=0; while((int) V.size() > 1){ // cerr << "! " << V.size() << '\n'; // cerr << "WTF : "; // for(auto Y : V) // cerr << Y.size() << ' '; // cerr << '\n'; L = 1, R = V.size(); while(L + 1 < R){ mid = (L + R) >> 1; if(Ask(0, mid) < mid) R = mid; else L = mid; } int res = R - 1; L = 0, R = res; while(L + 1 < R){ mid = (L + R) >> 1; if(Ask(mid, res + 1) < (res + 1 - mid)) L = mid; else R = mid; } // cerr << "# " << L << ' ' << res << '\n'; Comb(L, res); } for(auto &x : V[0]) x++; // cerr << "! " << n << ' ' << V[0].size() << '\n'; Answer(V[0]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...