#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
ll v[223456];
#define fi first
#define se second
void upmax(ll &x,ll y) {
x=max(x,y);
}
long long findGap(int T, int n)
{
ll ans=0;
if (T==1) {
int l=0, r=n-1;
MinMax(0ll,(1ll<<60),&v[0],&v[n-1]);
for (int i=0;i<n/2;i++) {
if (l+1==r) break;
MinMax(v[l]+1,v[r]-1,&v[l+1],&v[r-1]);
l++;
r--;
}
for (int i=1;i<n;i++) {
ans=max(ans,v[i]-v[i-1]);
}
return ans;
} else {
ll L,R;
MinMax(0ll,(1ll<<60),&L,&R);
set<pair<ll,pair<ll,ll> > > s;
s.insert({L-R,{L,R}});
ll lf=0,rg;
do {
ll d=-s.begin()->fi;
if (d<=ans) {
// cout<<ans<<endl;
return ans;
}
ll x=s.begin()->se.fi;
ll y=s.begin()->se.se;
s.erase(s.begin());
ll f=d/3;
ll m1,m2;
//cout<< x << ' ' << y <<'\t'<<ans<<endl;
MinMax(x+f,x+f+f,&m1,&m2);
//cout<<m1<<' '<<m2<<endl;
if (m1==-1) {
ll mn1,mx1,mn2,mx2;
if (x+1>x+f-1) mn1=mx1=-1; else MinMax(x+1,x+f-1,&mn1,&mx1);
if (x+2*f+1>y-1) mn2=mx2=-1; else MinMax(x+2*f+1,y-1,&mn2,&mx2);
//cout<<' '<<mn1<<' '<<mn2<<endl;
if (mn1==-1&&mn2==-1){
// cout<<max(ans,d)<<endl;
return max(ans,d);
}
else {
if (mx1!=-1&&mn2!=-1) upmax(ans,mn2-mx1);
if(mn1==-1) {
upmax(ans,mn2-x);
} else {
upmax(ans,mn1-x);
s.insert({mn1-mx1,{mn1,mx1}});
if (mn2!=-1) s.insert({mx1-mn2,{mn1,mn2}});
}
if(mn2==-1) {
upmax(ans,y-mx1);
} else {
upmax(ans,y-mx2);
s.insert({mn2-mx2,{mn2,mx2}});
}
}
} else {
s.insert({x-m1,{x,m1}});
s.insert({m2-y,{m2,y}});
if (m1 != m2) s.insert({m1-m2,{m1,m2}});
}
} while (!s.empty());
}
//cout<<"ANS="<<ans<<endl;
return ans;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:40:16: warning: unused variable 'lf' [-Wunused-variable]
ll lf=0,rg;
^~
gap.cpp:40:21: warning: unused variable 'rg' [-Wunused-variable]
ll lf=0,rg;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
640 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
680 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
2 ms |
788 KB |
Output is correct |
15 |
Correct |
2 ms |
872 KB |
Output is correct |
16 |
Correct |
15 ms |
1548 KB |
Output is correct |
17 |
Correct |
20 ms |
2012 KB |
Output is correct |
18 |
Correct |
15 ms |
2492 KB |
Output is correct |
19 |
Correct |
15 ms |
2932 KB |
Output is correct |
20 |
Correct |
11 ms |
3168 KB |
Output is correct |
21 |
Correct |
70 ms |
6240 KB |
Output is correct |
22 |
Correct |
78 ms |
7964 KB |
Output is correct |
23 |
Correct |
74 ms |
9808 KB |
Output is correct |
24 |
Correct |
75 ms |
11780 KB |
Output is correct |
25 |
Correct |
49 ms |
12856 KB |
Output is correct |
26 |
Correct |
70 ms |
14688 KB |
Output is correct |
27 |
Correct |
66 ms |
15348 KB |
Output is correct |
28 |
Correct |
54 ms |
15348 KB |
Output is correct |
29 |
Correct |
67 ms |
15348 KB |
Output is correct |
30 |
Correct |
47 ms |
15464 KB |
Output is correct |
31 |
Correct |
2 ms |
15464 KB |
Output is correct |
32 |
Correct |
2 ms |
15464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
15464 KB |
Output is correct |
2 |
Correct |
2 ms |
15464 KB |
Output is correct |
3 |
Correct |
2 ms |
15464 KB |
Output is correct |
4 |
Correct |
2 ms |
15464 KB |
Output is correct |
5 |
Correct |
2 ms |
15464 KB |
Output is correct |
6 |
Correct |
2 ms |
15464 KB |
Output is correct |
7 |
Correct |
2 ms |
15464 KB |
Output is correct |
8 |
Correct |
2 ms |
15464 KB |
Output is correct |
9 |
Correct |
2 ms |
15464 KB |
Output is correct |
10 |
Correct |
2 ms |
15464 KB |
Output is correct |
11 |
Correct |
3 ms |
15464 KB |
Output is correct |
12 |
Partially correct |
3 ms |
15464 KB |
Partially correct |
13 |
Correct |
3 ms |
15464 KB |
Output is correct |
14 |
Correct |
3 ms |
15464 KB |
Output is correct |
15 |
Partially correct |
3 ms |
15464 KB |
Partially correct |
16 |
Partially correct |
13 ms |
15464 KB |
Partially correct |
17 |
Partially correct |
13 ms |
15464 KB |
Partially correct |
18 |
Partially correct |
11 ms |
15464 KB |
Partially correct |
19 |
Partially correct |
11 ms |
15464 KB |
Partially correct |
20 |
Correct |
5 ms |
15464 KB |
Output is correct |
21 |
Partially correct |
48 ms |
15608 KB |
Partially correct |
22 |
Partially correct |
49 ms |
15736 KB |
Partially correct |
23 |
Partially correct |
49 ms |
15736 KB |
Partially correct |
24 |
Partially correct |
45 ms |
15736 KB |
Partially correct |
25 |
Partially correct |
117 ms |
20856 KB |
Partially correct |
26 |
Partially correct |
39 ms |
20856 KB |
Partially correct |
27 |
Partially correct |
53 ms |
20856 KB |
Partially correct |
28 |
Partially correct |
50 ms |
20856 KB |
Partially correct |
29 |
Partially correct |
49 ms |
20856 KB |
Partially correct |
30 |
Correct |
15 ms |
20856 KB |
Output is correct |
31 |
Correct |
2 ms |
20856 KB |
Output is correct |
32 |
Correct |
2 ms |
20856 KB |
Output is correct |