# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
200763 |
2020-02-08T05:39:49 Z |
Nordway |
Gap (APIO16_gap) |
C++14 |
|
67 ms |
1944 KB |
#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 ans=0;
ll mn,mx;
MinMax(l,r,&mn,&mx);
if(n==2)return mx-mn;
l=mn,r=mx;
MinMax(l+1,r-1,&mn,&mx);
if(r-mx>mn-l){
ans=r-mx;
r=mx;
while(r-l>1){
MinMax(max(l+1,r-ans),r-1,&mn,&mx);
if(mx==-1){
if(l+1<r-ans){
ll dist=r-l;
ll p=2,q=dist/ans+(dist%ans>0);
while(p<=q){
ll mid=(p+q)/2;
MinMax(max(l+1,r-ans*mid),r-1,&mn,&mx);
if(mn!=-1)break;
p=mid+1;
}
if(mn==-1)break;
ans=r-mx;
r=mx;
}
else break;
}
else{
r=mn;
}
}
}
else{
ans=mn-l;
l=mn;
while(r-l>1){
MinMax(l+1,min(r-1,l+ans),&mn,&mx);
if(mn==-1){
if(r-1<l+ans)break;
else{
ll dist=r-l;
ll p=2,q=dist/ans+(dist%ans>0);
while(p<=q){
ll mid=(p+q)/2;
MinMax(l+1,(r-1,l+ans*mid),&mn,&mx);
if(mn!=-1)break;
p=mid+1;
}
if(mn==-1)break;
ans=mn-l;
l=mn;
}
}
else{
l=mx;
}
}
}
return ans;
}
}
Compilation message
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:143:28: warning: left operand of comma operator has no effect [-Wunused-value]
MinMax(l+1,(r-1,l+ans*mid),&mn,&mx);
~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
248 KB |
Output is correct |
6 |
Correct |
5 ms |
248 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
5 ms |
248 KB |
Output is correct |
10 |
Correct |
5 ms |
248 KB |
Output is correct |
11 |
Correct |
5 ms |
248 KB |
Output is correct |
12 |
Correct |
5 ms |
248 KB |
Output is correct |
13 |
Correct |
5 ms |
248 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
248 KB |
Output is correct |
16 |
Correct |
17 ms |
632 KB |
Output is correct |
17 |
Correct |
17 ms |
632 KB |
Output is correct |
18 |
Correct |
17 ms |
636 KB |
Output is correct |
19 |
Correct |
18 ms |
632 KB |
Output is correct |
20 |
Correct |
13 ms |
632 KB |
Output is correct |
21 |
Correct |
54 ms |
1784 KB |
Output is correct |
22 |
Correct |
54 ms |
1784 KB |
Output is correct |
23 |
Correct |
54 ms |
1784 KB |
Output is correct |
24 |
Correct |
58 ms |
1784 KB |
Output is correct |
25 |
Correct |
45 ms |
1784 KB |
Output is correct |
26 |
Correct |
58 ms |
1912 KB |
Output is correct |
27 |
Correct |
56 ms |
1916 KB |
Output is correct |
28 |
Correct |
55 ms |
1784 KB |
Output is correct |
29 |
Correct |
55 ms |
1784 KB |
Output is correct |
30 |
Correct |
39 ms |
1944 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
5 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Partially correct |
5 ms |
376 KB |
Partially correct |
3 |
Partially correct |
5 ms |
252 KB |
Partially correct |
4 |
Partially correct |
4 ms |
252 KB |
Partially correct |
5 |
Partially correct |
4 ms |
248 KB |
Partially correct |
6 |
Partially correct |
4 ms |
248 KB |
Partially correct |
7 |
Partially correct |
5 ms |
248 KB |
Partially correct |
8 |
Partially correct |
5 ms |
252 KB |
Partially correct |
9 |
Partially correct |
5 ms |
252 KB |
Partially correct |
10 |
Partially correct |
5 ms |
248 KB |
Partially correct |
11 |
Partially correct |
5 ms |
248 KB |
Partially correct |
12 |
Partially correct |
6 ms |
376 KB |
Partially correct |
13 |
Partially correct |
6 ms |
248 KB |
Partially correct |
14 |
Partially correct |
5 ms |
248 KB |
Partially correct |
15 |
Partially correct |
5 ms |
376 KB |
Partially correct |
16 |
Partially correct |
13 ms |
504 KB |
Partially correct |
17 |
Partially correct |
16 ms |
504 KB |
Partially correct |
18 |
Partially correct |
14 ms |
524 KB |
Partially correct |
19 |
Partially correct |
15 ms |
504 KB |
Partially correct |
20 |
Partially correct |
11 ms |
504 KB |
Partially correct |
21 |
Partially correct |
40 ms |
1144 KB |
Partially correct |
22 |
Partially correct |
42 ms |
1120 KB |
Partially correct |
23 |
Partially correct |
46 ms |
1084 KB |
Partially correct |
24 |
Partially correct |
39 ms |
1144 KB |
Partially correct |
25 |
Partially correct |
67 ms |
1212 KB |
Partially correct |
26 |
Partially correct |
40 ms |
1016 KB |
Partially correct |
27 |
Partially correct |
39 ms |
1016 KB |
Partially correct |
28 |
Partially correct |
41 ms |
1144 KB |
Partially correct |
29 |
Partially correct |
40 ms |
996 KB |
Partially correct |
30 |
Partially correct |
36 ms |
1184 KB |
Partially correct |
31 |
Correct |
5 ms |
248 KB |
Output is correct |
32 |
Correct |
4 ms |
252 KB |
Output is correct |