Submission #1039792

# Submission time Handle Problem Language Result Execution time Memory
1039792 2024-07-31T09:08:46 Z 42kangaroo Radio Towers (IOI22_towers) C++17
17 / 100
1131 ms 5580 KB
#include "towers.h"
#include "bits/stdc++.h"

using namespace std;

struct SegTeRan {
	vector<int> a;

	int get(int l, int r, int i, int lq, int rq) {
		if (r <= lq || rq <= l) return 0;
		if (lq <= l && r <= rq) return a[i];
		int m = (l + r)/2;
		return max(get(l, m, 2*i + 1, lq, rq), get(m, r, 2*i + 2, lq, rq));
	}

	int set(int l, int r, int i, int k, int v) {
		if (k < l || r <= k) return a[i];
		if (l + 1 == r) return a[i] = v;
		int m = (l + r)/2;
		return a[i] = max(set(l, m, 2*i + 1, k, v), set(m, r, 2*i + 2, k, v));
	}
};


struct SegTeMa{
	vector<int> a;

	int build(int l, int r, int i, vector<int>& in) {
		if (l + 1 == r) return a[i] = in[l];
		int m = (l + r)/2;
		return a[i] = max(build(l, m, 2*i + 1, in), build(m, r, 2*i + 2, in));
	}

	int firLe(int l, int r, int i, int k, int hi) {
		if (l > k) return -1;
		if (a[i] < hi) return -1;
		if (l + 1 == r) return l;
		int m = (l + r)/2;
		int reR = firLe(m, r, 2*i + 2, k, hi);
		if (reR != -1) return reR;
		return firLe(l, m, 2*i + 1, k, hi);
	}

	int firRi(int l, int r, int i, int k, int hi) {
		if (r <= k) return -1;
		if (a[i] < hi) return -1;
		if (l + 1 == r) return l;
		int m = (l + r)/2;
		int reR = firRi(l, m, 2*i + 1, k, hi);
		if (reR != -1) return reR;
		return firRi(m, r, 2*i + 2, k, hi);
	}
};

vector<int> ch;

void init(int N, std::vector<int> H) {
	SegTeMa maSe{vector<int>(4*N)};
	SegTeRan raSe{vector<int>(4*N, 0)};
	maSe.build(0, N, 0, H);
	vector<int> o(N);
	std::iota(o.begin(), o.end(),0);
	std::sort(o.begin(), o.end(), [&](int l, int r){return H[l] < H[r];});
	for (int i = 0; i < N; ++i) {
		int l = 0, r = 1e9 + 1;
		while (l + 1 < r) {
			int m = l + (r  - l)/2;
			int leB = maSe.firLe(0, N, 0, o[i], H[o[i]] + m), reB = maSe.firRi(0, N, 0, o[i], H[o[i]] + m);
			if (leB == -1) leB = 0;
			if (reB == -1) reB = N;
			if (raSe.get(0, N, 0, leB, reB) < m) l = m;
			else r = m;
		}
		raSe.set(0, N, 0, o[i], l);
		ch.push_back(l);
	}
	std::sort(ch.begin(), ch.end());
}


int max_towers(int L, int R, int D) {
	return std::upper_bound(ch.rbegin(), ch.rend(),D, greater<>()) - ch.rbegin();
}
# Verdict Execution time Memory Grader output
1 Incorrect 549 ms 3428 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 910 ms 5172 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 306 ms 1516 KB Output is correct
2 Correct 1073 ms 5172 KB Output is correct
3 Correct 1014 ms 5580 KB Output is correct
4 Correct 1094 ms 5296 KB Output is correct
5 Correct 1124 ms 5324 KB Output is correct
6 Correct 1109 ms 5324 KB Output is correct
7 Correct 1033 ms 5324 KB Output is correct
8 Correct 975 ms 5280 KB Output is correct
9 Correct 955 ms 5324 KB Output is correct
10 Correct 1025 ms 5224 KB Output is correct
11 Correct 1131 ms 5328 KB Output is correct
12 Correct 476 ms 5324 KB Output is correct
13 Correct 486 ms 5308 KB Output is correct
14 Correct 482 ms 5328 KB Output is correct
15 Correct 329 ms 5216 KB Output is correct
16 Correct 483 ms 5156 KB Output is correct
17 Correct 432 ms 5068 KB Output is correct
18 Correct 497 ms 5336 KB Output is correct
19 Correct 537 ms 5244 KB Output is correct
20 Correct 440 ms 5128 KB Output is correct
21 Correct 454 ms 5296 KB Output is correct
22 Correct 447 ms 5356 KB Output is correct
23 Correct 448 ms 5360 KB Output is correct
24 Correct 355 ms 5324 KB Output is correct
25 Correct 338 ms 5180 KB Output is correct
26 Correct 501 ms 5156 KB Output is correct
27 Correct 358 ms 5224 KB Output is correct
28 Correct 10 ms 344 KB Output is correct
29 Correct 6 ms 536 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 5 ms 528 KB Output is correct
33 Correct 3 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 7 ms 520 KB Output is correct
37 Correct 7 ms 528 KB Output is correct
38 Correct 7 ms 344 KB Output is correct
39 Correct 7 ms 344 KB Output is correct
40 Correct 5 ms 344 KB Output is correct
41 Correct 5 ms 524 KB Output is correct
42 Correct 5 ms 344 KB Output is correct
43 Correct 6 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 549 ms 3428 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -