Submission #1082242

# Submission time Handle Problem Language Result Execution time Memory
1082242 2024-08-31T01:08:39 Z s_tree Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 12528 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int root = 0;
int par[N];
int L[N], R[N], mn[N];

struct ST {
	vector<pair<int,int>> t;
	int n;
	ST(){}
	ST(vector<int>&h) {
		n  = h.size();
		t.resize(2*n);
		for(int i = 0;i<n;i++)t[i+n] = {h[i], i};
		for(int i = n-1;i>0;i--)t[i] = max(t[2*i], t[2*i+1]);
	}
	int query(int l, int r) {
		l+=n,r+=n+1;
		pair<int,int> ans = {-1, -1};	
		for(;l<r;l>>=1,r>>=1) {
			if(l&1)ans = max(ans, t[l++]);
			if(r&1)ans = max(ans, t[--r]);
		}
		return ans.second;
	}
};
struct ST2 {
	vector<int> t;
	int n;
	ST2(){}
	ST2(vector<int>&h) {
		n  = h.size();
		t.resize(2*n);
		for(int i = 0;i<n;i++)t[i+n] = h[i];
		for(int i = n-1;i>0;i--)t[i] = min(t[2*i], t[2*i+1]);
	}
	int query(int l, int r) {
		l+=n,r+=n+1;
		int ans = 2e9;
		for(;l<r;l>>=1,r>>=1) {
			if(l&1)ans = min(ans, t[l++]);
			if(r&1)ans = min(ans, t[--r]);
		}
		return ans;
	}
};
vector<int> H;
ST st;
ST2 st2;
int build(int l, int r) {
	if(r < l)return -1;
	int p = st.query(l, r);
	L[p] = build(l, p-1);
	R[p] = build(p+1, r);
	mn[p] = H[p];
	if(L[p]!=-1)mn[p] = min(mn[p], mn[L[p]]);
	if(R[p]!=-1)mn[p] = min(mn[p], mn[R[p]]);
	return p;
}
void init(int n, std::vector<int> h) {
	st = ST(h);
	st2 = ST2(h);
	H = h;
	root = build(0, n-1);
}


int query(int v, int l, int r, int MX, int D) {
	if(l > r)return 0;
	if(v == -1)return 0;
	if(v > r) {
		return query(L[v], l, r, MX, D);
	}
	if(v < l)
		return query(R[v], l, r, MX, D);
	int ans = 0;	
	if(st2.query(l, r) <= MX)ans=1;
	ans = max(ans, query(L[v], l, v-1, H[v]-D, D)+query(R[v], v+1, r, H[v]-D, D));
	return ans;
}
int max_towers(int l, int r, int D) {
  return query(root, l, r, 2e9, D);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4064 ms 6756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 11 ms 3416 KB Output is correct
37 Correct 14 ms 4952 KB Output is correct
38 Correct 14 ms 4952 KB Output is correct
39 Correct 13 ms 4952 KB Output is correct
40 Correct 13 ms 4952 KB Output is correct
41 Correct 13 ms 5040 KB Output is correct
42 Correct 12 ms 4952 KB Output is correct
43 Correct 26 ms 11352 KB Output is correct
44 Correct 23 ms 11352 KB Output is correct
45 Correct 22 ms 9560 KB Output is correct
46 Correct 21 ms 8892 KB Output is correct
47 Correct 14 ms 4936 KB Output is correct
48 Correct 13 ms 4952 KB Output is correct
49 Correct 20 ms 4952 KB Output is correct
50 Correct 25 ms 11184 KB Output is correct
51 Correct 25 ms 11096 KB Output is correct
52 Correct 15 ms 5112 KB Output is correct
53 Correct 13 ms 4952 KB Output is correct
54 Correct 21 ms 4952 KB Output is correct
55 Correct 37 ms 12460 KB Output is correct
56 Correct 37 ms 11720 KB Output is correct
57 Correct 17 ms 4952 KB Output is correct
58 Correct 23 ms 4940 KB Output is correct
59 Correct 24 ms 4944 KB Output is correct
60 Correct 13 ms 5044 KB Output is correct
61 Correct 21 ms 5044 KB Output is correct
62 Correct 15 ms 4948 KB Output is correct
63 Correct 16 ms 4952 KB Output is correct
64 Correct 36 ms 12528 KB Output is correct
65 Correct 28 ms 12496 KB Output is correct
66 Correct 26 ms 9424 KB Output is correct
67 Correct 35 ms 11976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4089 ms 4952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4098 ms 1368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 11 ms 3416 KB Output is correct
37 Correct 14 ms 4952 KB Output is correct
38 Correct 14 ms 4952 KB Output is correct
39 Correct 13 ms 4952 KB Output is correct
40 Correct 13 ms 4952 KB Output is correct
41 Correct 13 ms 5040 KB Output is correct
42 Correct 12 ms 4952 KB Output is correct
43 Correct 26 ms 11352 KB Output is correct
44 Correct 23 ms 11352 KB Output is correct
45 Correct 22 ms 9560 KB Output is correct
46 Correct 21 ms 8892 KB Output is correct
47 Correct 14 ms 4936 KB Output is correct
48 Correct 13 ms 4952 KB Output is correct
49 Correct 20 ms 4952 KB Output is correct
50 Correct 25 ms 11184 KB Output is correct
51 Correct 25 ms 11096 KB Output is correct
52 Correct 15 ms 5112 KB Output is correct
53 Correct 13 ms 4952 KB Output is correct
54 Correct 21 ms 4952 KB Output is correct
55 Correct 37 ms 12460 KB Output is correct
56 Correct 37 ms 11720 KB Output is correct
57 Correct 17 ms 4952 KB Output is correct
58 Correct 23 ms 4940 KB Output is correct
59 Correct 24 ms 4944 KB Output is correct
60 Correct 13 ms 5044 KB Output is correct
61 Correct 21 ms 5044 KB Output is correct
62 Correct 15 ms 4948 KB Output is correct
63 Correct 16 ms 4952 KB Output is correct
64 Correct 36 ms 12528 KB Output is correct
65 Correct 28 ms 12496 KB Output is correct
66 Correct 26 ms 9424 KB Output is correct
67 Correct 35 ms 11976 KB Output is correct
68 Execution timed out 4089 ms 4952 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4064 ms 6756 KB Time limit exceeded
2 Halted 0 ms 0 KB -