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 "gap.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
#define fi first
#define se second
#define left BAO
#define right ANH
#define pb push_back
#define pf push_front
#define mp make_pair
#define ins insert
#define btpc __builtin_popcount
#define btclz __builtin_clz
#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template<class X, class Y>
bool minimize(X &x, const Y &y) {
if (x > y)
{
x = y;
return true;
}
return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
if (x < y)
{
x = y;
return true;
}
return false;
}
const int MOD = 1e9 + 7; //998244353
template<class X, class Y>
void add(X &x, const Y &y) {
x = (x + y);
if(x >= MOD) x -= MOD;
}
template<class X, class Y>
void sub(X &x, const Y &y) {
x = (x - y);
if(x < 0) x += MOD;
}
/* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/
const ll INF = 1e18;
const int N = 1e5 + 10;
ll findGap(int t, int n) {
if(t == 1) {
ll a, b;
set<ll> num;
MinMax(0, INF, &a, &b);
num.ins(a); num.ins(b);
int cnt = 2;
while(cnt < n) {
ll s, t;
MinMax(a + 1, b - 1, &s, &t);
num.ins(s);
num.ins(t);
cnt += 2;
a = s;
b = t;
}
vector<ll> c;
for(auto x : num) c.pb(x);
ll ans = 0;
for(int i = 0; i + 1 < c.size(); i++) {
maximize(ans, c[i + 1] - c[i]);
}
return ans;
}
ll a, b;
MinMax(0, INF, &a, &b);
ll d = (b - a - 1) / (n - 1);
ll c = (b - a - 1) % n;
ll l = a + 1;
ll ans = 0, last = a;
for(int i = 1; i < n; i++) {
ll r = l + d + (i <= c) - 1;
ll s, t;
MinMax(l, r, &s, &t);
if(s == -1) {
l = r + 1;
continue;
}
maximize(ans, s - last);
last = t;
l = r + 1;
}
maximize(ans, b - last);
return ans;
};
Compilation message (stderr)
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i = 0; i + 1 < c.size(); i++) {
| ~~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |