Submission #672286

#TimeUsernameProblemLanguageResultExecution timeMemory
672286Dan4LifeGap (APIO16_gap)C++17
30 / 100
44 ms2304 KiB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) (int)a.size()
const int maxn = 5e5+10;
const ll LINF = (ll)2e18;

ll ans=1,mn,mx,nn;
set<ll> S;

void query(ll l, ll r, ll &mn, ll &mx){
	if(l<=r) MinMax(l,r,&mn,&mx);
	else mn=-1,mx=-1;
}

void dnc(ll l, ll r){
	S.insert(l), S.insert(r);
	if(r-l<=ans) return;
	if(sz(S)==nn) return;

	ll mid = (l+r)/2ll, FF=-1, SS=-1;

	query(l+1,mid,mn,mx);
	if(mn!=-1 and mx!=-1) dnc(mn, mx); SS=mx;

	query(mid+1,r-1,mn,mx);
	if(mn!=-1 and mx!=-1) dnc(mn, mx); FF=mn;

	if(FF!=-1 and SS!=-1) ans = max(ans,FF-SS);
}

ll findGap(int T, int n)
{
	ll s=0, t=LINF; ans=1; S.clear();
	if(T==1){
		vector<ll> v; v.clear(); int x = (n+1)/2;
		while(x--) MinMax(s,t,&mn,&mx), v.pb(mn), v.pb(mx), s=mn+1, t=mx-1;
		sort(all(v));
		for(int i = 0; i < sz(v)-1; i++) 
			ans = max(ans, v[i+1]-v[i]);
		return ans;
	}
	MinMax(s,t,&mn,&mx), dnc(mn,mx);
	while(sz(S)>1){
		auto itr = S.begin(); auto itr2 = itr; itr2++;
		ans = max(ans, *itr2-*itr); S.erase(S.begin());
	}
	return ans;
}

Compilation message (stderr)

gap.cpp: In function 'void dnc(ll, ll)':
gap.cpp:29:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   29 |  if(mn!=-1 and mx!=-1) dnc(mn, mx); SS=mx;
      |  ^~
gap.cpp:29:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   29 |  if(mn!=-1 and mx!=-1) dnc(mn, mx); SS=mx;
      |                                     ^~
gap.cpp:32:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   32 |  if(mn!=-1 and mx!=-1) dnc(mn, mx); FF=mn;
      |  ^~
gap.cpp:32:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   32 |  if(mn!=-1 and mx!=-1) dnc(mn, mx); FF=mn;
      |                                     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...