This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "gap.h"
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
template<class T,int SZ> struct BIT{
T t[SZ];
void upd(int x,T y){
for(int i=x;i<SZ;i=(i|(i+1))){
t[i]+=y;
}
}
T pref(int x){
T res=0;
for(int i=x;i>=0;i=(i&(i+1))-1){
res+=t[i];
}
return res;
}
T get(int l,int r){
return pref(r)-pref(l-1);
}
};
template<class T,int SZ> struct ST{
T t[4*SZ];
void build(T a[],int v,int tl,int tr){
if(tl==tr){
t[v]=a[tl];
return ;
}
int tm=(tl+tr)/2;
build(a,v*2,tl,tm);
build(a,v*2+1,tm+1,tr);
t[v]=t[v*2]+t[v*2+1];
}
void upd(int v,int tl,int tr,int pos,T val){
if(tl==tr){
t[v]+=val;
return ;
}
int tm=(tl+tr)/2;
if(pos<=tm)upd(v*2,tl,tm,pos,val);
else upd(v*2+1,tm+1,tr,pos,val);
t[v]=t[v*2]+t[v*2+1];
}
T get(int v,int tl,int tr,int l,int r){
if(tl>r||l>tr)return 0;
if(l<=tl&&tr<=r)return t[v];
int tm=(tl+tr)/2;
return get(v*2,tl,tm,l,r)+get(v*2+1,tm+1,tr,l,r);
}
};
const int N=1e5+11;
const int M=1e3+11;
const int W=1e3+11;
const int inf=INT_MAX;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
ll a[N];
ll findGap(int T,int n){
ll l=0,r=INF;
if(T==1){
ll ans=0;
for(int i=1;i<=(n+1)/2;i++){
ll nl=l,nr=r;
MinMax(l,r,&nl,&nr);
int j=n-i+1;
a[i]=nl;
a[j]=nr;
l=nl+1,r=nr-1;
}
for(int i=1;i<n;i++){
ans=max(ans,a[i+1]-a[i]);
}
return ans;
}
else{
ll mn,mx;
MinMax(l,r,&mn,&mx);
l=1,r=INF-1;
ll ans=0;
while(l<=r){
ll m=(l+r)/2;
ll x=mn;
int w=2;
while(x<mx){
ll p,q;
MinMax(x+1,min(mx,x+m),&p,&q);
if(p==-1&&q==-1){
if(x+m>mx)w=0;
else w=1;
break;
}
x=q;
}
if(w==2)ans=m,l=m+1;
else if(w==1)l=m+1;
else r=m-1;
}
return ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |