Submission #81217

#TimeUsernameProblemLanguageResultExecution timeMemory
81217AngelKnowsGap (APIO16_gap)C++14
30 / 100
85 ms2300 KiB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
ll mn,mx;
ll l,r,mid;
ll a[100005];
int h,t;
ll ans;
unsigned long long now,pre;
unsigned long long len;
long long findGap(int T, int N)
{
	if (T==1) {
		h=0,t=N+1;
		l=0,r=1e18+1;
		for (;;) {
			MinMax(l,r,&mn,&mx);
			a[++h]=mn,a[--t]=mx;
			l=mn+1,r=mx-1;
			if (h>=t-1) break;
		}
		for (int i=1;i<=N-1;i++) {
			ll t=a[i+1]-a[i];
			if (t>ans) ans=t;
		}
	} else {
		now=-1;
		len=1;
		pre=-1;
		ll top=mx;
		while (now+1<=top) {
			ll t=top;
			if (now+len<t) t=now+len; 
			MinMax(now+1,t,&mn,&mx);
			if (mn==-1) {
				now+=len;
				len*=2;
			} else if (pre==-1) {
				now=mn;
				pre=mn;
				len=1;
			} else {
				ans=max(ans,mn-(ll)pre);
				now=mx;
				pre=mx;
				len=1; 
			}
		}
	}
	return ans;
}

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (now+1<=top) {
          ~~~~~^~~~~
gap.cpp:35:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (now+len<t) t=now+len; 
        ~~~~~~~^~
gap.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    } else if (pre==-1) {
               ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...