# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
631633 | minhcool | Gap (APIO16_gap) | C++17 | 0 ms | 0 KiB |
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>
using namespace std;
#include "gap.h"
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
//const int N = ;
const int oo = 1e18 + 7, mod = 1e9 + 7;
const int N = 5e5 + 5;
long long int findgap(int T, int N){
if(T == 1){
long long lstx = 0, lsty = 1e18, a, b;
set<long long> se;
for(int i = 1; i <= (N + 1) / 2; i++){
MinMax(lstx, lsty, &a, &b);
if(a != -1) se.insert(a);
if(b != -1) se.insert(b);
lstx = a + 1, lsty = b - 1;
}
vector<long long> arr;
for(auto it : se) arr.pb(it);
long long answer = 0;
for(int i = 1; i < arr.size(); i++){
answer = max(answer, arr[i] - arr[i - 1]);
}
return answer;
}
else{
long long mini, maxi;
MinMax(0, 1e18, &mini, &maxi);
long long gap = (maxi - mini - 1) / (N - 1);// exist a gap where no numbers in there => ans >= gap => same gap don't care
long long le = mini + 1, answer = 0, lst = mini;
while(le + gap <= maxi){
long long temp1, temp2;
MinMax(le, le + gap - 1, &temp1, &temp2);
le += gap;
if(temp1 == -1) continue;
answer = max(answer, temp1 - lst);
lst = temp2;
}
if(le < maxi){
long long temp1, temp2;
MinMax(le, maxi - 1, &temp1, &temp2);
if(temp1 == -1) continue;
answer = max(answer, temp1 - lst);
lst = temp2;
}
answer = max(answer, maxi - lst);
return answer;
}
}