66982023-12-17 16:26:07111Kazamatacpp17Wrong answer 0/40114ms15656 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

struct Fenwick {
	vector<int> v;

	Fenwick(int n) : v(n + 1) {
	}

	void add(int i, int x) {
		i++;
		for (int j = i; j < v.size(); j += j & -j) {
			v[j] += x;
		}
	}

	int sum(int i) {
		i++;
		int x = 0;
		for (int j = i; j > 0; j -= j & -j) {
			x += v[j];
		}
		return x;
	}
};

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be2.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	int l = 0, h = N;
	while (l < h) {
		int m = (l + h) / 2;
		Fenwick f(N * 2);
		bool ok = true;
		for (int i = 0; i < N; i++) {
			f.add(v[i], 1);
			f.add(v[i] + m + 1, -1);
			if (!f.sum(i) && !f.sum(N + i)) {
				ok = false;
				break;
			}
		}
		if (!ok) {
			l = m + 1;
		}
		else {
			h = m;
		}
	}
	cout << l << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Accepted0/03ms1828 KiB
2Wrong answer0/037ms4692 KiB
3Wrong answer0/23ms2680 KiB
4Wrong answer0/23ms2624 KiB
5Wrong answer0/23ms2868 KiB
6Wrong answer0/23ms3060 KiB
7Wrong answer0/23ms2952 KiB
8Wrong answer0/23ms3040 KiB
9Wrong answer0/23ms3248 KiB
10Wrong answer0/23ms3412 KiB
11Wrong answer0/297ms8540 KiB
12Wrong answer0/293ms9052 KiB
13Wrong answer0/271ms9644 KiB
14Wrong answer0/261ms10576 KiB
15Wrong answer0/2104ms11112 KiB
16Wrong answer0/290ms11920 KiB
17Wrong answer0/290ms12628 KiB
18Wrong answer0/282ms13288 KiB
19Wrong answer0/292ms13820 KiB
20Wrong answer0/2114ms14460 KiB
21Wrong answer0/264ms14928 KiB
22Wrong answer0/283ms15656 KiB