답안 #101834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101834 2019-03-20T12:39:20 Z cerberus Gap (APIO16_gap) C++17
30 / 100
86 ms 1528 KB
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

#ifndef LOCAL
#include "gap.h"
#endif

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll INF = 1e18;

ll findGap(int T, int N);
ll findGap_small(int N);
void query(ll s, ll t, ll &mn, ll &mx, int T);

int M;
set<pll> S;

#ifdef LOCAL
int main() {
	int T, n; cin >> T >> n;
	vector<ll> v(n);
	for (int i = 1; i <= n; ++i) {
		cin >> v[i - 1];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; ++i) {
		S.insert({v[i], i});
	}
	S.insert({-1, -1});
	S.insert({INF + 1, n});
	cout << findGap(T, n) << endl << M << ' ';
	if (T == 1) {
		cout << (n + 1) / 2 << endl;
	} else {
		cout << 3 * n << endl;
	}
}
#endif

ll findGap(int T, int N) {
	if (T == 1) {
		return findGap_small(N);
	}

	ll mn, mx;
	query(0, INF, mn, mx, T);
	if (N <= 2) {
		return mx - mn;
	}

	ll A = mn, B = mx, best = (B - A + N - 2) / (N - 1), sz = best + 1;
	while (A < B) {
		if (A + sz >= B) {
			query(A + 1, B - 1, mn, mx, T);
			mx = B;
			if (mn == -1) {
				mn = B;
			}
		} else {
			query(A + 1, A + sz, mn, mx, T);
		}
		if (mn == -1) {
			sz *= 2;
			continue;
		}
		best = max(best, mn - A);
		A = mx;
	}
	return best;
}

ll findGap_small(int N) {
	ll mn, mx;
	query(0, INF, mn, mx, 1);
	ll best = 0;
	ll A = mn, B = mx;
	N -= 2;
	while (A < B and N > 0) {
		query(A + 1, B - 1, mn, mx, 1);
		if (mn == -1) {
			best = max(best, B - A);
			break;
		} else {
			best = max(best, mn - A);
			best = max(best, B - mx);
			A = mn; B = mx;
			N -= 2;
		}
	}
	return max(best, B - A);
}

void query(ll s, ll t, ll &mn, ll &mx, int T) {
	if (s > t) {
		mn = mx = -1;
		return;
	}
#ifdef LOCAL
	assert(s <= t);
	++M;
	auto l = S.lower_bound({s, -INF});
	auto r = S.upper_bound({t, INF + 10});
	--r;
	if (l->second <= r->second) {
		mn = l->first;
		mx = r->first;
		if (T == 2) {
			M += (r->second - l->second + 1);
		}
	} else {
		mn = mx = -1;
	}
#else
	MinMax(s, t, &mn, &mx);
#endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 15 ms 888 KB Output is correct
17 Correct 9 ms 896 KB Output is correct
18 Correct 14 ms 1024 KB Output is correct
19 Correct 17 ms 896 KB Output is correct
20 Correct 11 ms 640 KB Output is correct
21 Correct 52 ms 1456 KB Output is correct
22 Correct 65 ms 1480 KB Output is correct
23 Correct 57 ms 1400 KB Output is correct
24 Correct 50 ms 1400 KB Output is correct
25 Correct 59 ms 1400 KB Output is correct
26 Correct 51 ms 1408 KB Output is correct
27 Correct 60 ms 1400 KB Output is correct
28 Correct 52 ms 1400 KB Output is correct
29 Correct 59 ms 1400 KB Output is correct
30 Correct 40 ms 1408 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 13 ms 896 KB Output is correct
17 Incorrect 11 ms 896 KB Output isn't correct
18 Correct 12 ms 896 KB Output is correct
19 Correct 15 ms 896 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 34 ms 1356 KB Output is correct
22 Correct 34 ms 1400 KB Output is correct
23 Correct 38 ms 1528 KB Output is correct
24 Correct 37 ms 1400 KB Output is correct
25 Correct 86 ms 1400 KB Output is correct
26 Correct 34 ms 1400 KB Output is correct
27 Incorrect 36 ms 1372 KB Output isn't correct
28 Incorrect 33 ms 1400 KB Output isn't correct
29 Correct 34 ms 1384 KB Output is correct
30 Correct 18 ms 1400 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct