Submission #106967

#TimeUsernameProblemLanguageResultExecution timeMemory
106967golubGap (APIO16_gap)C++14
0 / 100
38 ms1528 KiB
#include "gap.h"
#include<bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define pb push_back
#define pii pair<long long, long long>
#define len(x) (long long)x.size()

template<typename A, typename B>
bool cmax(A &a, const B &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename A, typename B>
bool cmin(A &a, const B &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int askcount = 0;

pii ask(long long s, long long t) {
	askcount++;
	long long mn = 0, mx = 0;
	MinMax(s, t, &mn, &mx);
	return {mn, mx};
}

long long findGap(int T, int N) {
	vector<long long> a;
	long long l = -1, r = (long long)1e18 + 1;
	MinMax(l, r, &l, &r);
	a.pb(l); a.pb(r);
	int dx = (r - l) / (N - 1);
	int MAX = r;
	r = l + dx;
	while (l < MAX) {
		pii res = ask(l, r);
		if (res.F != -1) a.pb(res.F);
		if (res.S != -1) a.pb(res.S);
		l += dx;
		r += dx;
	}
	long long best = -1;
	sort(all(a));
	// for (auto x: a) cout << x << "\n";
	for (int i = 0; i < len(a) - 1; i++) {
		cmax(best, a[i + 1] - a[i]);
	}
	return best;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...