답안 #639766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639766 2022-09-11T15:04:31 Z study 송신탑 (IOI22_towers) C++17
54 / 100
4000 ms 9416 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5, half = 1e5+1;
int n, a[MAXN],segt[200003],psum[MAXN+1];
vector<pair<int,int>> answers;

int query(int l, int r){
	l += half;
	r += half;
	int ans = 0;
	while (l <= r){
		if (l&1){
			ans = max(ans,segt[l]);
			l++;
		}
		if (r%2 == 0){
			ans = max(ans,segt[r]);
			r--;
		}
		l >>= 1;
		r >>= 1;
	}
	return ans;
}

void modify(int node, int val){
	node += half;
	segt[node] = val;
	node >>= 1;
	while (node){
		segt[node] = max(segt[2*node],segt[2*node+1]);
		node >>= 1;
	}
}

void init(int N, vector<int> H){
	n = N;
	for (int i=0; i<n; ++i){
		a[i] = H[i];
		modify(i,a[i]);
	}
	for (int i=0; i<n; ++i){
		if ((i == 0 or a[i] < a[i-1]) and (i == n-1 or a[i] < a[i+1])){
			psum[i+1]++;
		}
		psum[i+1] += psum[i];
	}
	vector<pair<int,int>> v,deltas;
	for (int i=0; i<n; ++i){
		v.emplace_back(a[i],i);
	}
	sort(v.begin(),v.end());
	set<int> pos = {INT_MIN,INT_MAX};
	for (auto i:v){
		auto it = pos.upper_bound(i.second);
		int A = *it,maxi=INT_MAX;
		it--;
		int B = *it;
		bool ok = false;
		if (A != INT_MAX){
			if (i.second == A-1) ok = true;
			maxi = min(maxi,query(i.second,A));
		}
		if (B != INT_MIN){
			if (B == i.second-1) ok = true;
			maxi = min(maxi,query(B,i.second));
		}
//		cout << maxi << ' ' << i.first << endl;
		if (maxi != i.first and !ok){
			if (maxi == INT_MAX) deltas.emplace_back(maxi,i.second);
			else deltas.emplace_back(max(1,maxi-i.first),i.second);
		}
		pos.emplace(i.second);
	}
	sort(deltas.rbegin(),deltas.rend());
//	for (auto i:deltas) cout << i.first << ' ' << i.second << endl;
	int val = INT_MAX, occ = 0;
	for (auto i:deltas){
		if (val == i.first){
			++occ;
		}
		else{
			answers.emplace_back(val,occ);
			val = i.first;
			occ++;
		}
	}
	answers.emplace_back(val,occ);
	reverse(answers.begin(),answers.end());
//	for (auto i:answers) cout << i.first << ' ' << i.second << endl;
}
int max_towers(int L, int R, int D){
	if (L == 0 and R == n-1){
//		for (auto i:answers) cout << i.first << ' ' << i.second << '\n';
		int idx = lower_bound(answers.begin(),answers.end(),make_pair(D,0))-answers.begin();
		return answers[idx].second;
	}
	if (D == 1){
		int ans = 0;
		if (L < R and a[L] < a[L+1]) ++ans;
		if (L < R and a[R] < a[R-1]) ++ans;
		L++; R++;
		if (L == R) return 1;
		return psum[R-1]-psum[L]+ans;
	}
	set<int> st;
	vector<pair<int,int>> v;
	for (int i=L; i<=R; ++i){
		v.emplace_back(a[i],i);
	}
	sort(v.begin(),v.end());
	int ans = 0;
	for (auto k:v){
		int i = k.second;
		if (st.empty()){
			st.emplace(i);
			++ans;
			continue;
		}
		auto it = st.upper_bound(i);
		int A = *it;
		--it;
		int B = *it;
		if ((*st.rbegin() < i or query(i,A)-D >= max(a[A],a[i])) and (*st.begin() > i or query(B,i)-D >= max(a[B],a[i]))){
			st.emplace(i);
			++ans;
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4078 ms 4892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 1 ms 428 KB Output is correct
29 Correct 1 ms 476 KB Output is correct
30 Correct 2 ms 408 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 1 ms 428 KB Output is correct
29 Correct 1 ms 476 KB Output is correct
30 Correct 2 ms 408 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 52 ms 6048 KB Output is correct
37 Correct 78 ms 9100 KB Output is correct
38 Correct 85 ms 9096 KB Output is correct
39 Correct 73 ms 9376 KB Output is correct
40 Correct 75 ms 9412 KB Output is correct
41 Correct 92 ms 9368 KB Output is correct
42 Correct 73 ms 9404 KB Output is correct
43 Correct 60 ms 8076 KB Output is correct
44 Correct 51 ms 8108 KB Output is correct
45 Correct 52 ms 7996 KB Output is correct
46 Correct 56 ms 8084 KB Output is correct
47 Correct 74 ms 9148 KB Output is correct
48 Correct 68 ms 9308 KB Output is correct
49 Correct 67 ms 9368 KB Output is correct
50 Correct 53 ms 8092 KB Output is correct
51 Correct 50 ms 8032 KB Output is correct
52 Correct 73 ms 9276 KB Output is correct
53 Correct 67 ms 9364 KB Output is correct
54 Correct 74 ms 9388 KB Output is correct
55 Correct 47 ms 8016 KB Output is correct
56 Correct 52 ms 7996 KB Output is correct
57 Correct 69 ms 8632 KB Output is correct
58 Correct 70 ms 9040 KB Output is correct
59 Correct 75 ms 9148 KB Output is correct
60 Correct 66 ms 9392 KB Output is correct
61 Correct 66 ms 9412 KB Output is correct
62 Correct 69 ms 9324 KB Output is correct
63 Correct 71 ms 9328 KB Output is correct
64 Correct 51 ms 8040 KB Output is correct
65 Correct 55 ms 8028 KB Output is correct
66 Correct 52 ms 8060 KB Output is correct
67 Correct 47 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 631 ms 9136 KB Output is correct
2 Correct 950 ms 9108 KB Output is correct
3 Correct 886 ms 9152 KB Output is correct
4 Correct 652 ms 9344 KB Output is correct
5 Correct 866 ms 9416 KB Output is correct
6 Correct 746 ms 9352 KB Output is correct
7 Correct 894 ms 9408 KB Output is correct
8 Correct 855 ms 8088 KB Output is correct
9 Correct 886 ms 8060 KB Output is correct
10 Correct 680 ms 8088 KB Output is correct
11 Correct 863 ms 7996 KB Output is correct
12 Correct 823 ms 8076 KB Output is correct
13 Correct 796 ms 8000 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 84 ms 9172 KB Output is correct
18 Correct 77 ms 9360 KB Output is correct
19 Correct 66 ms 9368 KB Output is correct
20 Correct 48 ms 8032 KB Output is correct
21 Correct 48 ms 8132 KB Output is correct
22 Correct 71 ms 9104 KB Output is correct
23 Correct 70 ms 9396 KB Output is correct
24 Correct 71 ms 9376 KB Output is correct
25 Correct 52 ms 8072 KB Output is correct
26 Correct 51 ms 8024 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 436 KB Output is correct
33 Correct 2 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 2336 KB Output is correct
2 Correct 746 ms 9100 KB Output is correct
3 Correct 693 ms 9112 KB Output is correct
4 Correct 713 ms 9320 KB Output is correct
5 Correct 921 ms 9336 KB Output is correct
6 Correct 872 ms 9344 KB Output is correct
7 Correct 935 ms 9416 KB Output is correct
8 Correct 754 ms 8060 KB Output is correct
9 Correct 950 ms 8048 KB Output is correct
10 Correct 708 ms 8096 KB Output is correct
11 Correct 789 ms 8008 KB Output is correct
12 Correct 76 ms 9120 KB Output is correct
13 Correct 71 ms 9404 KB Output is correct
14 Correct 68 ms 9308 KB Output is correct
15 Correct 46 ms 8100 KB Output is correct
16 Correct 52 ms 8084 KB Output is correct
17 Correct 66 ms 8596 KB Output is correct
18 Correct 69 ms 9100 KB Output is correct
19 Correct 76 ms 9108 KB Output is correct
20 Correct 74 ms 9372 KB Output is correct
21 Correct 77 ms 9412 KB Output is correct
22 Correct 66 ms 9364 KB Output is correct
23 Correct 68 ms 9404 KB Output is correct
24 Correct 50 ms 8120 KB Output is correct
25 Correct 47 ms 8008 KB Output is correct
26 Correct 50 ms 8116 KB Output is correct
27 Correct 47 ms 8124 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 432 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 1 ms 428 KB Output is correct
29 Correct 1 ms 476 KB Output is correct
30 Correct 2 ms 408 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 52 ms 6048 KB Output is correct
37 Correct 78 ms 9100 KB Output is correct
38 Correct 85 ms 9096 KB Output is correct
39 Correct 73 ms 9376 KB Output is correct
40 Correct 75 ms 9412 KB Output is correct
41 Correct 92 ms 9368 KB Output is correct
42 Correct 73 ms 9404 KB Output is correct
43 Correct 60 ms 8076 KB Output is correct
44 Correct 51 ms 8108 KB Output is correct
45 Correct 52 ms 7996 KB Output is correct
46 Correct 56 ms 8084 KB Output is correct
47 Correct 74 ms 9148 KB Output is correct
48 Correct 68 ms 9308 KB Output is correct
49 Correct 67 ms 9368 KB Output is correct
50 Correct 53 ms 8092 KB Output is correct
51 Correct 50 ms 8032 KB Output is correct
52 Correct 73 ms 9276 KB Output is correct
53 Correct 67 ms 9364 KB Output is correct
54 Correct 74 ms 9388 KB Output is correct
55 Correct 47 ms 8016 KB Output is correct
56 Correct 52 ms 7996 KB Output is correct
57 Correct 69 ms 8632 KB Output is correct
58 Correct 70 ms 9040 KB Output is correct
59 Correct 75 ms 9148 KB Output is correct
60 Correct 66 ms 9392 KB Output is correct
61 Correct 66 ms 9412 KB Output is correct
62 Correct 69 ms 9324 KB Output is correct
63 Correct 71 ms 9328 KB Output is correct
64 Correct 51 ms 8040 KB Output is correct
65 Correct 55 ms 8028 KB Output is correct
66 Correct 52 ms 8060 KB Output is correct
67 Correct 47 ms 8024 KB Output is correct
68 Correct 631 ms 9136 KB Output is correct
69 Correct 950 ms 9108 KB Output is correct
70 Correct 886 ms 9152 KB Output is correct
71 Correct 652 ms 9344 KB Output is correct
72 Correct 866 ms 9416 KB Output is correct
73 Correct 746 ms 9352 KB Output is correct
74 Correct 894 ms 9408 KB Output is correct
75 Correct 855 ms 8088 KB Output is correct
76 Correct 886 ms 8060 KB Output is correct
77 Correct 680 ms 8088 KB Output is correct
78 Correct 863 ms 7996 KB Output is correct
79 Correct 823 ms 8076 KB Output is correct
80 Correct 796 ms 8000 KB Output is correct
81 Correct 0 ms 336 KB Output is correct
82 Correct 2 ms 464 KB Output is correct
83 Correct 1 ms 464 KB Output is correct
84 Correct 84 ms 9172 KB Output is correct
85 Correct 77 ms 9360 KB Output is correct
86 Correct 66 ms 9368 KB Output is correct
87 Correct 48 ms 8032 KB Output is correct
88 Correct 48 ms 8132 KB Output is correct
89 Correct 71 ms 9104 KB Output is correct
90 Correct 70 ms 9396 KB Output is correct
91 Correct 71 ms 9376 KB Output is correct
92 Correct 52 ms 8072 KB Output is correct
93 Correct 51 ms 8024 KB Output is correct
94 Correct 1 ms 464 KB Output is correct
95 Correct 1 ms 464 KB Output is correct
96 Correct 1 ms 464 KB Output is correct
97 Correct 1 ms 464 KB Output is correct
98 Correct 1 ms 464 KB Output is correct
99 Correct 1 ms 436 KB Output is correct
100 Correct 2 ms 464 KB Output is correct
101 Correct 1 ms 464 KB Output is correct
102 Correct 1 ms 464 KB Output is correct
103 Correct 1 ms 464 KB Output is correct
104 Execution timed out 4014 ms 7968 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4078 ms 4892 KB Time limit exceeded
2 Halted 0 ms 0 KB -