Submission #740480

# Submission time Handle Problem Language Result Execution time Memory
740480 2023-05-12T14:42:03 Z alex_2008 Radio Towers (IOI22_towers) C++17
4 / 100
927 ms 21884 KB
//#include "towers.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
int ind = -1;
bool ch = true;
vector <int> h;
const int N = 100100, M = 20;
int mx[N][M], Left[N], Right[N];
void init(int n, vector<int> a) {
	ch = true;
	ind = -1;
	h = a;
	for (int i = 0; i < n - 1; ++i)
	{
		if (a[i] > a[i + 1]) {
			if (ind == -1) ind = i;
		}
		else {
			if (ind != -1) ch = false;
		}
	}
	for (int i = 0; i < n; i++) {
		mx[i][0] = a[i];
	}
	for (int j = 1; j < 20; j++) {
		for (int i = n - 1; i >= 0; i--) {
			mx[i][j] = max(mx[i][j - 1], mx[min(n, i + (1 << (j - 1)))][j - 1]);
		}
	}
}
int findmaxinrange(int L, int R) {
	int u = log2(R - L + 1);
	return max(mx[L][u], mx[R - (1 << u) + 1][u]);
}
int max_towers(int L, int R, int D) {
	if (ch) {
		if (R < ind || L > ind) return 1;
		if (h[ind] >= (max(h[L], h[R]) + D)) return 2;
		return 1;
	}
	int n = (int)h.size();
	vector <pair<int, int>> v;
	set <int> ms;
	for (int i = 0; i < n; i++) {
		int l = 0, r = i - 1;
		Left[i] = -1;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (findmaxinrange(mid, i - 1) >= h[i] + D) {
				Left[i] = mid;
				l = mid + 1;
			}
			else r = mid - 1;
		}
		Right[i] = -1;
		l = i + 1, r = n - 1;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (findmaxinrange(i + 1, mid) >= h[i] + D) {
				Right[i] = mid;
				r = mid - 1;
			}
			else l = mid + 1;
		}
		v.push_back({h[i], i});
	}
	int ans = 0;
	sort(v.begin(), v.end());
	for (auto it : v) {
		int ind = it.second;
		if (ind > R || ind < L) continue;
		if (Left[ind] != -1) {
			auto it = ms.lower_bound(ind); --it;
			if (it != ms.end() && *it > Left[ind]) {
				continue;
			}
		}
		if (Right[ind] != -1) {
			auto it = ms.lower_bound(ind);
			if (it != ms.end() && *it < Right[ind]) {
				continue;	
			}
		}
		ms.insert(ind);
		++ans;
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 259 ms 5584 KB Output is correct
2 Correct 835 ms 9256 KB Output is correct
3 Correct 772 ms 9264 KB Output is correct
4 Correct 700 ms 9268 KB Output is correct
5 Correct 927 ms 9268 KB Output is correct
6 Correct 737 ms 9256 KB Output is correct
7 Correct 645 ms 9272 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 21884 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 5656 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 259 ms 5584 KB Output is correct
2 Correct 835 ms 9256 KB Output is correct
3 Correct 772 ms 9264 KB Output is correct
4 Correct 700 ms 9268 KB Output is correct
5 Correct 927 ms 9268 KB Output is correct
6 Correct 737 ms 9256 KB Output is correct
7 Correct 645 ms 9272 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Runtime error 1 ms 464 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -