이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
long long findGap(int T, int N)
{
long long ans = 1;
if (T == 1){
long long s = -1,t = 1e18 + 1;
long long x = 0,y = 0;
vector<long long>pos(N);
int l = 0,r = N - 1;
while(l <= r && s<=t){
MinMax(s,t,&x,&y);
if (x == -1 && y == -1){
break;
}
pos[l] = x;
pos[r] = y;
--r;
++l;
s = x + 1;
t = y - 1;
}
sort(pos.begin(),pos.end());
for (int i = 1;i<N;++i){
ans = max(ans,pos[i] - pos[i - 1]);
}
}
else{
long long x,y;
vector<long long>v;
vector<long long>pos;
long long s = 0;
for (int i = 0;i<N;){
if (pos.empty()){
long long left = s + 1,right = 1e18;
while(left<=right){
long long mid = (left + right)>>1;
MinMax(s + 1,mid,&x,&y);
if (x == -1 && y == -1){
s = mid;
left = mid + 1;
}
else{
pos.push_back(y);
if (x != y){
pos.push_back(x);
}
right = mid - 1;
}
}
sort(pos.rbegin(),pos.rend());
}
if (pos.back() < s)pos.pop_back();
else if (pos.back() == s){
v.push_back(pos.back());
pos.pop_back();
++s;
++i;
}
else{
MinMax(s,pos.back(),&x,&y);
if (x == -1 && y == -1){
s = pos.back() + 1;
pos.pop_back();
}
else{
v.push_back(x);
s = x + 1;
++i;
}
}
}
sort(v.begin(),v.end());
for (int i = 1;i<N;++i){
ans = max(ans,v[i] - v[i - 1]);
}
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |