#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
const long long INF = 1e18;
long long findGap(int T, int N) {
multiset < pair< long long,pair<long long,long long> > > st;
long long mn, mx;
MinMax(0ll,INF,&mn,&mx);
st.insert({-(mx-mn),{mn,mx}});
long long ans = 0;
if(n == 2){
return mx - mn;
}
int kk = 0;
if(mn != -1) kk++;
if(mn != mx) kk++;
while(!st.empty()) {
long long L, R;
if(abs(st.begin()->first) <= ans)
return ans;
L = st.begin()->second.first;
R = st.begin()->second.second;
st.erase(st.begin());
long long a1, a2, a3, a4;
a1 = a1 = a3 = a4 = -1;
if(kk != n || L != (L+R)/2) {
MinMax(L,(L+R)/2,&a1,&a2);
if(a1 != -1) kk++;
if(a2 != a1) kk++;
}
if(kk != n || R != (L+R)/2+1) {
MinMax((L+R)/2+1,R,&a3,&a4);
if(a3 != -1) kk++;
if(a4 != a1) kk++;
}
if(a1 == a2 && a1 != -1)
ans = max(ans,a2-L);
if(a2-a1 == 1 && a1 != -1)
ans = max(ans,1ll);
if(a1-L == 1 && a1 != -1)
ans = max(ans,1ll);
if(a3 == a4 && a4 != -1)
ans = max(ans,R-a3);
if(a4-a3 == 1 && a3 != -1)
ans = max(ans,1ll);
if(R-a4 == 1 && a4 != -1)
ans = max(ans,1ll);
if(a2 != -1 && a3 != -1)
ans = max(ans,a3-a2);
if(a3 == -1 && a1 == -1)
ans = max(ans,R-L);
if(a1 == -1 && a3 != -1)
ans = max(ans,a3-L);
if(a3 == -1 && a2 != -1)
ans = max(ans,R-a2);
if(a1 != -1 && a1-L > 1)
st.insert({L-a1,{L,a1}});
if(a1 != -1 && a2-a1 > 1)
st.insert({a1-a2,{a1,a2}});
if(a1 != -1 && a3 != -1 && a3-a2 > 1)
st.insert({a2-a3,{a2,a3}});
if(a3 != -1 && a4-a3 > 1)
st.insert({a3-a4,{a3,a4}});
if(a3 != -1 && R-a4 > 1)
st.insert({a4-R,{a4,R}});
}
return ans;
return 0;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:15:8: error: 'n' was not declared in this scope
if(n == 2){
^
gap.cpp:32:25: warning: operation on 'a1' may be undefined [-Wsequence-point]
a1 = a1 = a3 = a4 = -1;
^
gap.cpp:33:20: error: 'n' was not declared in this scope
if(kk != n || L != (L+R)/2) {
^
gap.cpp:38:20: error: 'n' was not declared in this scope
if(kk != n || R != (L+R)/2+1) {
^