Submission #952575

#TimeUsernameProblemLanguageResultExecution timeMemory
952575GrindMachinePark (JOI17_park)C++17
67 / 100
358 ms848 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; #include "park.h" void Detect(int T, int n) { vector<bool> vis(n); vector<int> depth(n); vis[0] = 1; depth[0] = 0; auto f = [&](int u, int v, vector<int> place){ if(u == v) return 1; if(u > v) swap(u,v); int place_arr[n]; rep(i,n) place_arr[i] = place[i]; return Ask(u,v,place_arr); }; vector<pii> ans; while(count(all(vis),1) < n){ int u = -1; rep(i,n){ if(!vis[i]){ u = i; break; } } // largest depth active guy that is ancestor vector<pii> active_order; rep(i,n){ if(vis[i]){ active_order.pb({depth[i],i}); } } sort(all(active_order)); int l = 1, r = sz(active_order)-1; int ances = 0; while(l <= r){ int mid = (l+r) >> 1; vector<int> place(n,1); for(int i = mid; i < sz(active_order); ++i){ place[active_order[i].ss] = 0; } int res = f(u,0,place); if(!res){ ances = active_order[mid].ss; l = mid+1; } else{ r = mid-1; } } vis[u] = 1; vector<int> nodes; nodes.pb(u); while(true){ int l = 0, r = n-1; int pos = -1; vector<int> place(n); while(l <= r){ int mid = (l+r) >> 1; fill(all(place),1); rep(i,mid+1){ if(!vis[i]){ place[i] = 0; } } int res = f(u,0,place); if(!res){ pos = mid; r = mid-1; } else{ l = mid+1; } } if(pos == -1) break; nodes.pb(pos); vis[pos] = 1; } auto cmp = [&](int u, int v){ vector<int> place(n,1); place[u] = 0; int res = f(0,v,place); return !res; }; stable_sort(all(nodes),cmp); nodes.insert(nodes.begin(),ances); rep1(i,sz(nodes)-1){ int u = nodes[i], p = nodes[i-1]; depth[u] = depth[p]+1; ans.pb({u,p}); } } for(auto [u,v] : ans){ if(u > v) swap(u,v); Answer(u,v); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...