Submission #522381

# Submission time Handle Problem Language Result Execution time Memory
522381 2022-02-04T17:40:58 Z NicolaAbusaad2014 Gap (APIO16_gap) C++14
100 / 100
71 ms 3272 KB
/**
 * Prof.Nicola
**/
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;
#define endl "\n"
#define mp make_pair
#define F first
#define S second
#define REP(i,l,r) for(long long i=(l);i<(r);i++)
#define PER(i,l,r) for(long long i=(r)-1;i>=(l);i--)
#define bitl __builtin_clz
#define bitr __builtin_ctz
#define bits __builtin_popcount
const long dx[4]={1,0,-1,0},dz[4]={0,1,0,-1};
const long double pi=3.14159265359;
const long long mod=1e9+7;
long long p(long long x){while(x&(x-1)){x=x&(x-1);}return x;}
long long squared(long long x){return (x*x)%mod;}
long long power(long long x,long long p){if(p==0){return 1;}if(p%2==1){return (power(x,p-1)*x)%mod;}return squared(power(x,p/2));}
long long inv(long long x){return power(x,mod-2);}
long long log(long long x,long long z){if(x<z){return 0;}return 1+log(x/z,z);}
template<class T>void re(T&x){cin>>x;}
template<class T1,class T2> void re(pair<T1,T2>&x){re(x.first);re(x.second);}
template<class T>void re(vector<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T>void re(deque<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T>void out(T x){cout<<x<<" ";}
template<class T1,class T2>void out(pair<T1,T2>x){out(x.first);out(x.second);cout<<endl;}
template<class T>void out(vector<T>x,long l=0,long r=0){if(!r){r=x.size();}for(long i=l;i<r;i++){out(x[i]);}cout<<endl;}
template<class T>void out(deque<T>x,long l=0,long r=0){if(!r){r=x.size();}for(long i=l;i<r;i++){out(x[i]);}cout<<endl;}
template<class T>void out(set<T>x){while(!x.empty()){out(*x.begin());x.erase(*x.begin());}cout<<endl;}
template<class T1,class T2>void out(map<T1,T2>x){while(!x.empty()){out(*x.begin());x.erase(x.begin()->first);}cout<<endl;}
template<class T>void out(queue<T>x){while(!x.empty()){out(x.front());x.pop();}cout<<endl;}
template<class T>void out(priority_queue<T>x){while(!x.empty()){out(x.top());x.pop();}cout<<endl;}
template<class T>void out(stack<T>x){while(!x.empty()){out(x.top());x.pop();}cout<<endl;}
template<class T>T cross(complex<T>x,complex<T>z){return (conj(x)*z).imag();}
template<class T>T dot(complex<T>x,complex<T>z){return (conj(x)*z).real();}
set<long long>::iterator T;
long long vLE(long long x,vector<long long>&VT,long l=0,long r=-1){if(r==-1){r=VT.size()-1;}if(VT[l]>x){return -1;}long long z=p(r-l);while(z){if(l+z<=r&&VT[l+z]<=x){l+=z;}z/=2;}return l;}
long long vL(long long x,vector<long long>&VT,long l=0,long r=-1){if(r==-1){r=VT.size()-1;}if(VT[l]>=x){return -1;}long long z=p(r-l);while(z){if(l+z<=r&&VT[l+z]<x){l+=z;}z/=2;}return l;}
long long vGE(long long x,vector<long long>&VT,long l=0,long r=-1){if(r==-1){r=VT.size()-1;}if(VT[l]>=x){return l;}l=vL(x,VT,l,r);if(l==r){return -1;}return l+1;}
long long vG(long long x,vector<long long>&VT,long l=0,long r=-1){if(r==-1){r=VT.size()-1;}if(VT[l]>x){return l;}l=vLE(x,VT,l,r);if(l==r){return -1;}return l+1;}
long long sLE(long long x,set<long long>&ST){if(ST.count(x)){return x;}if(*ST.begin()>x){return -1;}ST.insert(x);T=ST.find(x);T--;ST.erase(x);return *T;}
long long sL(long long x,set<long long>&ST){if(*ST.begin()>=x){return -1;}if(ST.count(x)){T=ST.find(x);T--;return *T;}ST.insert(x);T=ST.find(x);T--;ST.erase(x);return *T;}
long long sGE(long long x,set<long long>&ST){if(ST.count(x)){return x;}if(*ST.rbegin()<x){return -1;}ST.insert(x);T=ST.find(x);T++;ST.erase(x);return *T;}
long long sG(long long x,set<long long>&ST){if(*ST.rbegin()<=x){return -1;}if(ST.count(x)){T=ST.find(x);T++;return *T;}ST.insert(x);T=ST.find(x);T++;ST.erase(x);return *T;}
long long subtask1(int N)
{
    long long a=0,b=1e18+5,mn,mx,ans=0;
    vector<long long>v;
    while(a<=b){
        if(v.size()==N){
            break;
        }
        MinMax(a,b,&mn,&mx);
        v.push_back(mn);
        v.push_back(mx);
        a=mn+1;
        b=mx-1;
    }
    sort(v.begin(),v.end());
    REP(i,1,v.size()){
        ans=max(ans,v[i]-v[i-1]);
    }
    return ans;
}
long long findGap(int T, int N)
{
    if(T==1){
        return subtask1(N);
    }
    long long n=N,a,b,mn,mx,dum=1e18+5,gap,ans=0;
    vector<long long>v;
    MinMax(0,dum,&a,&b);
    v.push_back(a);
    gap=(b-a+n-2)/(n-1);
    for(long long i=a+1;i<b;i+=gap){
        MinMax(i,i+gap-1,&mn,&mx);
        v.push_back(mn);
        v.push_back(mx);
    }
    v.push_back(b);
    sort(v.begin(),v.end());
    REP(i,1,v.size()){
        if(v[i-1]==-1){
            continue;
        }
        ans=max(ans,v[i]-v[i-1]);
    }
	return ans;
}

Compilation message

gap.cpp: In function 'long long int subtask1(int)':
gap.cpp:54:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |         if(v.size()==N){
      |            ~~~~~~~~^~~
gap.cpp:12:41: 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]
   12 | #define REP(i,l,r) for(long long i=(l);i<(r);i++)
      |                                         ^
gap.cpp:64:5: note: in expansion of macro 'REP'
   64 |     REP(i,1,v.size()){
      |     ^~~
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:12:41: 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]
   12 | #define REP(i,l,r) for(long long i=(l);i<(r);i++)
      |                                         ^
gap.cpp:86:5: note: in expansion of macro 'REP'
   86 |     REP(i,1,v.size()){
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 0 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 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 1 ms 328 KB Output is correct
16 Correct 11 ms 840 KB Output is correct
17 Correct 10 ms 840 KB Output is correct
18 Correct 14 ms 908 KB Output is correct
19 Correct 10 ms 800 KB Output is correct
20 Correct 9 ms 904 KB Output is correct
21 Correct 43 ms 2200 KB Output is correct
22 Correct 40 ms 2180 KB Output is correct
23 Correct 42 ms 2232 KB Output is correct
24 Correct 43 ms 2148 KB Output is correct
25 Correct 39 ms 2148 KB Output is correct
26 Correct 44 ms 2212 KB Output is correct
27 Correct 49 ms 2188 KB Output is correct
28 Correct 44 ms 2232 KB Output is correct
29 Correct 48 ms 2224 KB Output is correct
30 Correct 36 ms 2252 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 1 ms 268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 232 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 15 ms 1056 KB Output is correct
17 Correct 15 ms 1176 KB Output is correct
18 Correct 16 ms 1048 KB Output is correct
19 Correct 14 ms 1092 KB Output is correct
20 Correct 8 ms 1048 KB Output is correct
21 Correct 63 ms 3272 KB Output is correct
22 Correct 59 ms 3256 KB Output is correct
23 Correct 61 ms 3216 KB Output is correct
24 Correct 62 ms 3224 KB Output is correct
25 Correct 52 ms 3196 KB Output is correct
26 Correct 60 ms 3224 KB Output is correct
27 Correct 57 ms 3212 KB Output is correct
28 Correct 71 ms 3192 KB Output is correct
29 Correct 67 ms 3212 KB Output is correct
30 Correct 30 ms 3216 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 1 ms 200 KB Output is correct