Submission #400643

# Submission time Handle Problem Language Result Execution time Memory
400643 2021-05-08T12:46:33 Z A_D Gap (APIO16_gap) C++14
43.8651 / 100
335 ms 4276 KB
#include "gap.h"

#include <bits/stdc++.h>

#define ll long long

using namespace std;
/*
static void my_assert(int k){ if (!k) exit(1); }

static int subtask_num, N;
static long long A[100001];
static long long call_count;

long long findGap(int, int);

void MinMax(long long s, long long t, long long *mn, long long *mx)
{
	int lo = 1, hi = N, left = N+1, right = 0;
	my_assert(s <= t && mn != NULL && mx != NULL);
	while (lo <= hi){
		int mid = (lo+hi)>>1;
		if (A[mid] >= s) hi = mid - 1, left = mid;
		else lo = mid + 1;
	}
	lo = 1, hi = N;
	while (lo <= hi){
		int mid = (lo+hi)>>1;
		if (A[mid] <= t) lo = mid + 1, right = mid;
		else hi = mid - 1;
	}
	if (left > right) *mn = *mx = -1;
	else{
		*mn = A[left];
		*mx = A[right];
	}
	if (subtask_num == 1) call_count++;
	else if (subtask_num == 2) call_count += right-left+2;
}
*/
ll l2=0,r2=1e18;
ll *l1=&l2;
ll *r1=&r2;
vector <ll> vec;
set <ll> st;
ll n,q;
ll s(ll m)
{
    vector<ll> vec;
    ll l=0,r=1e18;
    l2=0,r2=1e18;
    while(l<=r&&m--){
        MinMax(l,r,l1,r1);
        if(l2!=-1)vec.push_back(l2);
        if(r2!=-1)vec.push_back(r2);
        l=l2;
        r=r2;
        l++;
        r--;
    }
    sort(vec.begin(),vec.end());
    ll ans=1;
    for(ll i=1;i<vec.size();i++)ans=max(ans,vec[i]-vec[i-1]);
    return ans;
}
void bs(ll l,ll r)
{
    if(l>r||n==0)return;
    ll mid=(l+r)/2;
//    cout<<l<<" "<<mid<<endl;
    MinMax(l,mid,l1,r1);
  //  cout<<l2<<" "<<r2<<endl;
    if(l2==-1){
        bs(mid+1,r);
    }
    else if(l2==r2){
        vec.push_back(l2);
        n--;
        st.insert(l2);
        bs(mid+1,r);
    }
    else if(l2+1==r2){
        vec.push_back(l2);
        vec.push_back(r2);
        n-=2;
        st.insert(l2);
        st.insert(r2);
        bs(mid+1,r);
    }
    else{
        n-=2;
        vec.push_back(l2);
        vec.push_back(r2);
        bs(l2+1,r2-1);
        bs(mid+1,r);
    }
}
ll s2()
{
    st.clear();vec.clear();
    ll l=0;
    ll r=1e18;
    bs(l,r);
    ll ans=1;
    sort(vec.begin(),vec.end());
    for(ll i=1;i<vec.size();i++)ans=max(ans,vec[i]-vec[i-1]);
    //for(auto x:vec)cout<<x<<" ";cout<<endl;
    return ans;
}
long long findGap(int T, int N)
{
    n=N;
    q=1;
    if(T==1)return s((N+1)/2);
    else{
        return s2();
    }
}
/*
int main()
{
	FILE *in = stdin, *out = stdout;
	my_assert(2 == fscanf(in, "%d%d", &subtask_num, &N));
	my_assert(1 <= subtask_num && subtask_num <= 2);
	my_assert(2 <= N && N <= 100000);
	for (int i=1;i<=N;i++) my_assert(1 == fscanf(in, "%lld", A+i));
	for (int i=1;i<N;i++) my_assert(A[i] < A[i+1]);
	fprintf(out, "%lld\n", findGap(subtask_num, N));
	fprintf(out, "%lld\n", call_count);
}
*/

Compilation message

gap.cpp: In function 'long long int s(long long int)':
gap.cpp:63:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(ll i=1;i<vec.size();i++)ans=max(ans,vec[i]-vec[i-1]);
      |                ~^~~~~~~~~~~
gap.cpp: In function 'long long int s2()':
gap.cpp:106:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for(ll i=1;i<vec.size();i++)ans=max(ans,vec[i]-vec[i-1]);
      |                ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 2 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
16 Correct 15 ms 840 KB Output is correct
17 Correct 13 ms 840 KB Output is correct
18 Correct 15 ms 840 KB Output is correct
19 Correct 12 ms 892 KB Output is correct
20 Correct 10 ms 876 KB Output is correct
21 Correct 50 ms 2232 KB Output is correct
22 Correct 50 ms 2236 KB Output is correct
23 Correct 49 ms 2220 KB Output is correct
24 Correct 56 ms 2204 KB Output is correct
25 Correct 45 ms 2224 KB Output is correct
26 Correct 51 ms 2192 KB Output is correct
27 Correct 50 ms 2196 KB Output is correct
28 Correct 50 ms 2196 KB Output is correct
29 Correct 49 ms 2204 KB Output is correct
30 Correct 42 ms 2228 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Partially correct 1 ms 200 KB Partially correct
3 Partially correct 1 ms 200 KB Partially correct
4 Partially correct 1 ms 200 KB Partially correct
5 Partially correct 1 ms 200 KB Partially correct
6 Partially correct 1 ms 200 KB Partially correct
7 Partially correct 1 ms 200 KB Partially correct
8 Partially correct 1 ms 200 KB Partially correct
9 Partially correct 1 ms 200 KB Partially correct
10 Partially correct 1 ms 328 KB Partially correct
11 Partially correct 4 ms 328 KB Partially correct
12 Partially correct 4 ms 328 KB Partially correct
13 Partially correct 4 ms 328 KB Partially correct
14 Partially correct 4 ms 328 KB Partially correct
15 Partially correct 3 ms 328 KB Partially correct
16 Partially correct 71 ms 960 KB Partially correct
17 Partially correct 71 ms 1028 KB Partially correct
18 Partially correct 73 ms 1096 KB Partially correct
19 Partially correct 72 ms 960 KB Partially correct
20 Partially correct 15 ms 1220 KB Partially correct
21 Partially correct 309 ms 3252 KB Partially correct
22 Partially correct 314 ms 3556 KB Partially correct
23 Partially correct 310 ms 3208 KB Partially correct
24 Partially correct 312 ms 3240 KB Partially correct
25 Partially correct 191 ms 3332 KB Partially correct
26 Partially correct 335 ms 3372 KB Partially correct
27 Partially correct 306 ms 3216 KB Partially correct
28 Partially correct 330 ms 3312 KB Partially correct
29 Partially correct 320 ms 3224 KB Partially correct
30 Partially correct 66 ms 4276 KB Partially correct
31 Partially correct 1 ms 200 KB Partially correct
32 Correct 1 ms 200 KB Output is correct