Submission #405659

#TimeUsernameProblemLanguageResultExecution timeMemory
405659Blistering_BarnaclesSwapping Cities (APIO20_swap)C++11
7 / 100
325 ms25148 KiB
//apig's property //Happiness can be found, even in the darkest of times, if one only remembers to turn on the light //El Pueblo Unido Jamas Sera Vencido //The saddest thing about betrayal? is that it never comes from your enemies //Do or do not... there is no try //Billions of bilious blue blistering barnacles in a thundering typhoon! #include "swap.h" #include<bits/stdc++.h> #define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) #define F first #define S second #define pb push_back #define vll vector< ll > #define vi vector< int > #define pll pair< ll , ll > #define pi pair< int , int > #define all(s) s.begin() , s.end() #define sz(s) s.size() #define str string #define md ((s + e) / 2) #define mid ((l + r) / 2) #define msdp(dp) memset(dp , -1 , sizeof dp) #define mscl(dp) memset(dp , 0 , sizeof dp) #define C continue #define R return #define B break #define lx node * 2 #define rx node * 2 + 1 #define br(o) o ; break #define co(o) o ; continue using namespace std; typedef int ll; ll q, dp[105][100005], a[555555] , b[555555], k, l, m, n, o, p; map < ll , ll > mp; vll adj[555555]; const ll mod = 1e9+7; str s; pll tree[555555] ; pll mrg(pll a , pll b){ ll o1 = a.F , o2 = a.S , p1 = b.F , p2 = b.S ; R { min(o1 , p1) , min( { max(p1 , o1) , p2 , o2 } ) } ; } void build(ll s , ll e , ll node){ if(s == e){ tree[node] = {a[s] , mod}; R ; } build(s , md , lx) , build(md + 1 , e , rx) ; tree[node] = mrg(tree[lx] , tree[rx]) ; } pll query(ll s , ll e , ll node , ll l , ll r){ if(s > r || e < l || l > r)R {mod , mod} ; if(l <= s && e <= r)R tree[node] ; R mrg(query(s , md , lx , l , r) , query(md + 1 , e , rx , l , r) ); } void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) { n = N ; for(ll i = 0 ; i < M ; i++){ a[V[i]] = W[i] ; } build(1 , n - 1 , 1) ; } int getMinimumFuelCapacity(int X, int Y) { o = X , p = Y ; if(o > p)swap(o , p) ; ll ans = -1 ; if(n <= 3)R ans ; pll o1 = query(1 , n - 1 , 1 , 1 , o - 1) , o2 = query(1 , n - 1 , 1 , o + 1 , p - 1) , o3 = query(1 , n - 1 , 1 , p + 1 , n - 1) ; pll res = mrg(mrg(o1 , o2) , o3) ; if(!o){ ans = max ( { a[p] , res.F , res.S } ) ; } else { ans = max ( { a[o] , a[p] , res.F } ) ; } R ans ; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...