답안 #832527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832527 2023-08-21T11:10:22 Z NothingXD 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 10540 KB
#include "towers.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}
 
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 1e5 + 10;
const int lg = 20;

int n, h[maxn], mx[lg][maxn], l[maxn], r[maxn], f[2][maxn];

void add(int *f, int idx, int x){
	for (; idx <= n; idx += idx & -idx) f[idx] += x;
}

void add(int *f, int l, int r, int x){
	add(f, l, x);
	add(f, r+1, -x);
}

int get(int *f, int idx){
	int res = 0;
	for (; idx; idx -= idx & -idx) res += f[idx];
	return res;
}

int get(int *f, int l, int r){
	if (r < l) return 0;
	return get(f, r) - get(f, l-1);
}

int getmax(int l, int r){
	r++;
	int x = 31 - __builtin_clz(r-l);
	return max(mx[x][l], mx[x][r-(1 << x)]);
}

void init(int N, std::vector<int> H) {
	n = N;
	for (int i = 0; i < n; i++){
		h[i] = H[i];
		mx[0][i] = h[i];
	}
	for (int i = 1; i < lg; i++){
		for (int j = 0; j + (1 << i) <= n; j++){
			mx[i][j] = max(mx[i-1][j], mx[i-1][j+(1<<(i-1))]);
		}
	}
}

int max_towers(int L, int R, int D) {
	memset(l, 0, sizeof l);
	memset(r, 0, sizeof r);
	memset(f, 0, sizeof f);
	for (int i = L; i <= R; i++){
		int lo = L, hi = i;
		while(lo + 1 < hi){
			int mid = (lo + hi) >> 1;
			if (getmax(mid, i-1) - D >= h[i]) lo = mid;
			else hi = mid;
		}
		l[i] = lo;
	}
	vector<pii> val;
	for (int i = L; i <= R; i++){
		int lo = i, hi = R;
		while(lo + 1 < hi){
			int mid = (lo + hi) >> 1;
			if (getmax(i+1, mid) - D >= h[i]) hi = mid;
			else lo = mid;
		}
		r[i] = hi;
		val.push_back({h[i], i});
	}

	//debug(1);

	sort(all(val));

	int ans = 0;

	for (auto [x, y]: val){
		if (get(f[0], y+1)) continue;
		if (get(f[1], l[y]+1, r[y]+1)) continue;
		ans++;
		add(f[0], l[y]+1, r[y]+1, 1);
		add(f[1], y+1, 1);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4011 ms 6860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1872 KB Output is correct
2 Correct 2 ms 2000 KB Output is correct
3 Correct 1 ms 2000 KB Output is correct
4 Correct 1 ms 2000 KB Output is correct
5 Correct 1 ms 2000 KB Output is correct
6 Correct 1 ms 2000 KB Output is correct
7 Correct 1 ms 2000 KB Output is correct
8 Correct 1 ms 2000 KB Output is correct
9 Correct 1 ms 2000 KB Output is correct
10 Correct 2 ms 2000 KB Output is correct
11 Correct 1 ms 2000 KB Output is correct
12 Correct 1 ms 1872 KB Output is correct
13 Correct 1 ms 2000 KB Output is correct
14 Correct 1 ms 2000 KB Output is correct
15 Correct 1 ms 2000 KB Output is correct
16 Correct 1 ms 2000 KB Output is correct
17 Correct 1 ms 2000 KB Output is correct
18 Correct 1 ms 2000 KB Output is correct
19 Correct 1 ms 2000 KB Output is correct
20 Correct 1 ms 2000 KB Output is correct
21 Correct 1 ms 2000 KB Output is correct
22 Correct 1 ms 2000 KB Output is correct
23 Correct 1 ms 1972 KB Output is correct
24 Correct 1 ms 2000 KB Output is correct
25 Correct 1 ms 1872 KB Output is correct
26 Correct 1 ms 1964 KB Output is correct
27 Correct 1 ms 2000 KB Output is correct
28 Correct 1 ms 1908 KB Output is correct
29 Correct 1 ms 1984 KB Output is correct
30 Correct 1 ms 2000 KB Output is correct
31 Correct 1 ms 2000 KB Output is correct
32 Correct 1 ms 2000 KB Output is correct
33 Correct 1 ms 2000 KB Output is correct
34 Correct 1 ms 2000 KB Output is correct
35 Correct 1 ms 2000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1872 KB Output is correct
2 Correct 2 ms 2000 KB Output is correct
3 Correct 1 ms 2000 KB Output is correct
4 Correct 1 ms 2000 KB Output is correct
5 Correct 1 ms 2000 KB Output is correct
6 Correct 1 ms 2000 KB Output is correct
7 Correct 1 ms 2000 KB Output is correct
8 Correct 1 ms 2000 KB Output is correct
9 Correct 1 ms 2000 KB Output is correct
10 Correct 2 ms 2000 KB Output is correct
11 Correct 1 ms 2000 KB Output is correct
12 Correct 1 ms 1872 KB Output is correct
13 Correct 1 ms 2000 KB Output is correct
14 Correct 1 ms 2000 KB Output is correct
15 Correct 1 ms 2000 KB Output is correct
16 Correct 1 ms 2000 KB Output is correct
17 Correct 1 ms 2000 KB Output is correct
18 Correct 1 ms 2000 KB Output is correct
19 Correct 1 ms 2000 KB Output is correct
20 Correct 1 ms 2000 KB Output is correct
21 Correct 1 ms 2000 KB Output is correct
22 Correct 1 ms 2000 KB Output is correct
23 Correct 1 ms 1972 KB Output is correct
24 Correct 1 ms 2000 KB Output is correct
25 Correct 1 ms 1872 KB Output is correct
26 Correct 1 ms 1964 KB Output is correct
27 Correct 1 ms 2000 KB Output is correct
28 Correct 1 ms 1908 KB Output is correct
29 Correct 1 ms 1984 KB Output is correct
30 Correct 1 ms 2000 KB Output is correct
31 Correct 1 ms 2000 KB Output is correct
32 Correct 1 ms 2000 KB Output is correct
33 Correct 1 ms 2000 KB Output is correct
34 Correct 1 ms 2000 KB Output is correct
35 Correct 1 ms 2000 KB Output is correct
36 Correct 12 ms 6608 KB Output is correct
37 Correct 21 ms 9500 KB Output is correct
38 Correct 15 ms 9012 KB Output is correct
39 Correct 19 ms 9272 KB Output is correct
40 Correct 15 ms 9000 KB Output is correct
41 Correct 31 ms 10248 KB Output is correct
42 Correct 18 ms 8748 KB Output is correct
43 Correct 20 ms 9684 KB Output is correct
44 Correct 14 ms 9016 KB Output is correct
45 Correct 12 ms 8892 KB Output is correct
46 Correct 12 ms 8756 KB Output is correct
47 Correct 20 ms 9536 KB Output is correct
48 Correct 16 ms 9252 KB Output is correct
49 Correct 14 ms 8900 KB Output is correct
50 Correct 15 ms 9216 KB Output is correct
51 Correct 17 ms 9628 KB Output is correct
52 Correct 41 ms 10308 KB Output is correct
53 Correct 43 ms 10296 KB Output is correct
54 Correct 34 ms 10264 KB Output is correct
55 Correct 26 ms 10304 KB Output is correct
56 Correct 26 ms 10268 KB Output is correct
57 Correct 34 ms 10024 KB Output is correct
58 Correct 36 ms 10292 KB Output is correct
59 Correct 36 ms 10304 KB Output is correct
60 Correct 36 ms 10360 KB Output is correct
61 Correct 35 ms 10304 KB Output is correct
62 Correct 43 ms 10344 KB Output is correct
63 Correct 44 ms 10284 KB Output is correct
64 Correct 27 ms 10264 KB Output is correct
65 Correct 26 ms 10264 KB Output is correct
66 Correct 28 ms 10312 KB Output is correct
67 Correct 26 ms 10300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4021 ms 10540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4097 ms 3928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1872 KB Output is correct
2 Correct 2 ms 2000 KB Output is correct
3 Correct 1 ms 2000 KB Output is correct
4 Correct 1 ms 2000 KB Output is correct
5 Correct 1 ms 2000 KB Output is correct
6 Correct 1 ms 2000 KB Output is correct
7 Correct 1 ms 2000 KB Output is correct
8 Correct 1 ms 2000 KB Output is correct
9 Correct 1 ms 2000 KB Output is correct
10 Correct 2 ms 2000 KB Output is correct
11 Correct 1 ms 2000 KB Output is correct
12 Correct 1 ms 1872 KB Output is correct
13 Correct 1 ms 2000 KB Output is correct
14 Correct 1 ms 2000 KB Output is correct
15 Correct 1 ms 2000 KB Output is correct
16 Correct 1 ms 2000 KB Output is correct
17 Correct 1 ms 2000 KB Output is correct
18 Correct 1 ms 2000 KB Output is correct
19 Correct 1 ms 2000 KB Output is correct
20 Correct 1 ms 2000 KB Output is correct
21 Correct 1 ms 2000 KB Output is correct
22 Correct 1 ms 2000 KB Output is correct
23 Correct 1 ms 1972 KB Output is correct
24 Correct 1 ms 2000 KB Output is correct
25 Correct 1 ms 1872 KB Output is correct
26 Correct 1 ms 1964 KB Output is correct
27 Correct 1 ms 2000 KB Output is correct
28 Correct 1 ms 1908 KB Output is correct
29 Correct 1 ms 1984 KB Output is correct
30 Correct 1 ms 2000 KB Output is correct
31 Correct 1 ms 2000 KB Output is correct
32 Correct 1 ms 2000 KB Output is correct
33 Correct 1 ms 2000 KB Output is correct
34 Correct 1 ms 2000 KB Output is correct
35 Correct 1 ms 2000 KB Output is correct
36 Correct 12 ms 6608 KB Output is correct
37 Correct 21 ms 9500 KB Output is correct
38 Correct 15 ms 9012 KB Output is correct
39 Correct 19 ms 9272 KB Output is correct
40 Correct 15 ms 9000 KB Output is correct
41 Correct 31 ms 10248 KB Output is correct
42 Correct 18 ms 8748 KB Output is correct
43 Correct 20 ms 9684 KB Output is correct
44 Correct 14 ms 9016 KB Output is correct
45 Correct 12 ms 8892 KB Output is correct
46 Correct 12 ms 8756 KB Output is correct
47 Correct 20 ms 9536 KB Output is correct
48 Correct 16 ms 9252 KB Output is correct
49 Correct 14 ms 8900 KB Output is correct
50 Correct 15 ms 9216 KB Output is correct
51 Correct 17 ms 9628 KB Output is correct
52 Correct 41 ms 10308 KB Output is correct
53 Correct 43 ms 10296 KB Output is correct
54 Correct 34 ms 10264 KB Output is correct
55 Correct 26 ms 10304 KB Output is correct
56 Correct 26 ms 10268 KB Output is correct
57 Correct 34 ms 10024 KB Output is correct
58 Correct 36 ms 10292 KB Output is correct
59 Correct 36 ms 10304 KB Output is correct
60 Correct 36 ms 10360 KB Output is correct
61 Correct 35 ms 10304 KB Output is correct
62 Correct 43 ms 10344 KB Output is correct
63 Correct 44 ms 10284 KB Output is correct
64 Correct 27 ms 10264 KB Output is correct
65 Correct 26 ms 10264 KB Output is correct
66 Correct 28 ms 10312 KB Output is correct
67 Correct 26 ms 10300 KB Output is correct
68 Execution timed out 4021 ms 10540 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4011 ms 6860 KB Time limit exceeded
2 Halted 0 ms 0 KB -