답안 #627343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627343 2022-08-12T13:10:23 Z minhcool 송신탑 (IOI22_towers) C++17
27 / 100
4000 ms 11700 KB
#include<bits/stdc++.h>
using namespace std;
 
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e5 + 5;
 
const int oo = 1e9 + 7, mod = 1e9 + 7;
 
int n, a[N];
 
int ind_mx = 1;
 
bool sub1 = 0;
 
void init(int _n, vector<int> _a){
	n = _n;
	for(int i = 0; i < n; i++) a[i + 1] = _a[i];
	for(int i = 2; i <= n; i++) if(a[i] > a[ind_mx]) ind_mx = i;
	sub1 = 1;
	for(int i = 1; i < ind_mx; i++) sub1 &= (a[i + 1] > a[i]);
	for(int i = ind_mx; i < n; i++) sub1 &= (a[i] > a[i + 1]);
}
 
int dp[N], lstl[N], lstr[N];
 
int mx[N][20], lg2[20];
 
int maxi(int l, int r){
	if(l > r) return 0;
	int k = lg2[r - l + 1];
	return max(mx[l][k], mx[r - (1LL << k) + 1][k]);
}
 
int IT[N << 2];
 
void upd(int id, int l, int r, int pos, int val){
	IT[id] = max(IT[id], val);
	if(l == r){
		return;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid) upd(id << 1, l, mid, pos, val);
	else upd(id << 1 | 1, mid + 1, r, pos, val);
}
 
int get(int id, int l, int r, int L, int R){
	if(l > R || r < L || L > R) return 0;
	if(l >= L && r <= R) return IT[id];
	int mid = (l + r) >> 1;
	return max(get(id << 1, l, mid, L, R), get(id << 1 | 1, mid + 1, r, L, R));
}
 
int max_towers(int l, int r, int d){
	l++, r++;
	if(sub1){
		if(r <= ind_mx || l >= ind_mx) return 1;
		else if(max(a[l], a[r]) > (a[ind_mx] - d)) return 1;
		else return 2;
	}
	else if(n <= 000){
		for(int i = l; i <= r; i++){
			lstl[i] = -oo, lstr[i] = oo;
			for(int j = i + 1; j <= r; j++){
				if(a[j] >= (a[i] + d)){
					lstr[i] = j;
					break;
				}
			}
			for(int j = i - 1; j >= l; j--){
				if(a[j] >= (a[i] + d)){
					lstl[i] = j;
					break;
				}
			}
			//cout << lstl[i] << " " << lstr[i] << "\n";
		}
		int mx = -1;
		for(int i = l; i <= r; i++){
			dp[i] = 0;
			for(int j = l; j <= i - 1; j++){
				if(lstl[i] < lstr[j]) continue;
				//cout << i << " " << j << "\n";
				dp[i] = max(dp[i], dp[j]);
			}
			dp[i]++;
			mx = max(mx, dp[i]);
		}
		return mx;
	}
	else{
		for(int i = l; i <= r; i++) mx[i][0] = a[i];
		for(int i = 1; i <= 19; i++){
			for(int j = l; j <= (r - (1LL << i) + 1); j++){
				mx[j][i] = max(mx[j][i - 1], mx[j + (1LL << (i - 1))][i - 1]);
			}
		}/*
		for(int i = l; i <= r; i++){
			if(maxi(i + 1, r) < (a[i] + d)) lstr[i] = oo;
			else{
				lstr[i] = i;
				for(int j = 19; j >= 0; j--){
					if(lstr[i] + (1LL << j) > r) continue;
					if(mx[lstr[i]][j] < (a[i] + d)){
						lstr[i] += (1LL << j);
						//cout << i << " " << j << "\n";
					}
				}
				//lstr[i]++;
			}
			if(maxi(l, i - 1) < (a[i] + d)) lstl[i] = -oo;
			else{
				lstl[i] = i;
				for(int j = 19; j >= 0; j--){
					if(lstl[i] - (1LL << j) < l) continue;
					if(mx[lstl[i] - (1LL << j) + 1][j] < (a[i] + d)) lstl[i] -= (1LL << j);
				}
				//lstl[i]--;
			}
			//cout << i << " " << lstl[i] << " " << lstr[i] << "\n";
		}*/
		for(int i = l; i <= r; i++){
			lstl[i] = -oo, lstr[i] = oo;
			for(int j = i + 1; j <= r; j++){
				if(a[j] >= (a[i] + d)){
					lstr[i] = j;
					break;
				}
			}
			for(int j = i - 1; j >= l; j--){
				if(a[j] >= (a[i] + d)){
					lstl[i] = j;
					break;
				}
			}
			//cout << lstl[i] << " " << lstr[i] << "\n";
		}
		int mx = -1;
		for(int i = 1; i <= (n << 2); i++) IT[i] = 0;
		for(int i = l; i <= r; i++){
			dp[i] = get(1, 1, n + 1, l, max(lstl[i], l - 1)) + 1;
			upd(1, 1, n + 1, min(r + 1, lstr[i]), dp[i]);
			mx = max(mx, dp[i]);
			//cout << i << " " << dp[i] << "\n";
		}
		return mx;
	}
}
 
/*
void process(){
	int n, q;
	vector<int> a;
	cin >> n >> q;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		a.pb(x);
	}
	init(n, a);
	while(q--){
		int l, r, d;
		cin >> l >> r >> d;
		cout << max_towers(l, r, d) << "\n";
	}
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	process();
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 936 KB Output is correct
2 Correct 707 ms 1448 KB Output is correct
3 Correct 670 ms 1488 KB Output is correct
4 Correct 825 ms 1444 KB Output is correct
5 Correct 789 ms 1340 KB Output is correct
6 Correct 702 ms 1360 KB Output is correct
7 Correct 683 ms 1448 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 2 ms 524 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 3 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 2 ms 524 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 3 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 21 ms 3536 KB Output is correct
37 Correct 390 ms 5812 KB Output is correct
38 Correct 45 ms 3904 KB Output is correct
39 Correct 366 ms 5532 KB Output is correct
40 Correct 29 ms 3760 KB Output is correct
41 Correct 1272 ms 10132 KB Output is correct
42 Correct 12 ms 2752 KB Output is correct
43 Correct 12 ms 1444 KB Output is correct
44 Correct 21 ms 1468 KB Output is correct
45 Correct 15 ms 2832 KB Output is correct
46 Correct 16 ms 2752 KB Output is correct
47 Correct 23 ms 5808 KB Output is correct
48 Correct 19 ms 4520 KB Output is correct
49 Correct 14 ms 3364 KB Output is correct
50 Correct 10 ms 1456 KB Output is correct
51 Correct 282 ms 6164 KB Output is correct
52 Correct 43 ms 11628 KB Output is correct
53 Correct 42 ms 11568 KB Output is correct
54 Correct 39 ms 11548 KB Output is correct
55 Correct 11 ms 1488 KB Output is correct
56 Correct 1716 ms 11660 KB Output is correct
57 Correct 2184 ms 11260 KB Output is correct
58 Correct 1704 ms 11576 KB Output is correct
59 Correct 935 ms 11596 KB Output is correct
60 Correct 82 ms 11524 KB Output is correct
61 Correct 884 ms 11532 KB Output is correct
62 Correct 1488 ms 11652 KB Output is correct
63 Correct 862 ms 11596 KB Output is correct
64 Correct 18 ms 1356 KB Output is correct
65 Correct 18 ms 1444 KB Output is correct
66 Correct 2169 ms 11616 KB Output is correct
67 Correct 3188 ms 11700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4080 ms 11624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4027 ms 3096 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 2 ms 524 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 3 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 21 ms 3536 KB Output is correct
37 Correct 390 ms 5812 KB Output is correct
38 Correct 45 ms 3904 KB Output is correct
39 Correct 366 ms 5532 KB Output is correct
40 Correct 29 ms 3760 KB Output is correct
41 Correct 1272 ms 10132 KB Output is correct
42 Correct 12 ms 2752 KB Output is correct
43 Correct 12 ms 1444 KB Output is correct
44 Correct 21 ms 1468 KB Output is correct
45 Correct 15 ms 2832 KB Output is correct
46 Correct 16 ms 2752 KB Output is correct
47 Correct 23 ms 5808 KB Output is correct
48 Correct 19 ms 4520 KB Output is correct
49 Correct 14 ms 3364 KB Output is correct
50 Correct 10 ms 1456 KB Output is correct
51 Correct 282 ms 6164 KB Output is correct
52 Correct 43 ms 11628 KB Output is correct
53 Correct 42 ms 11568 KB Output is correct
54 Correct 39 ms 11548 KB Output is correct
55 Correct 11 ms 1488 KB Output is correct
56 Correct 1716 ms 11660 KB Output is correct
57 Correct 2184 ms 11260 KB Output is correct
58 Correct 1704 ms 11576 KB Output is correct
59 Correct 935 ms 11596 KB Output is correct
60 Correct 82 ms 11524 KB Output is correct
61 Correct 884 ms 11532 KB Output is correct
62 Correct 1488 ms 11652 KB Output is correct
63 Correct 862 ms 11596 KB Output is correct
64 Correct 18 ms 1356 KB Output is correct
65 Correct 18 ms 1444 KB Output is correct
66 Correct 2169 ms 11616 KB Output is correct
67 Correct 3188 ms 11700 KB Output is correct
68 Execution timed out 4080 ms 11624 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 936 KB Output is correct
2 Correct 707 ms 1448 KB Output is correct
3 Correct 670 ms 1488 KB Output is correct
4 Correct 825 ms 1444 KB Output is correct
5 Correct 789 ms 1340 KB Output is correct
6 Correct 702 ms 1360 KB Output is correct
7 Correct 683 ms 1448 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 336 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 464 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 2 ms 524 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 2 ms 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 2 ms 464 KB Output is correct
41 Correct 2 ms 464 KB Output is correct
42 Correct 1 ms 208 KB Output is correct
43 Correct 1 ms 208 KB Output is correct
44 Correct 2 ms 464 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 21 ms 3536 KB Output is correct
47 Correct 390 ms 5812 KB Output is correct
48 Correct 45 ms 3904 KB Output is correct
49 Correct 366 ms 5532 KB Output is correct
50 Correct 29 ms 3760 KB Output is correct
51 Correct 1272 ms 10132 KB Output is correct
52 Correct 12 ms 2752 KB Output is correct
53 Correct 12 ms 1444 KB Output is correct
54 Correct 21 ms 1468 KB Output is correct
55 Correct 15 ms 2832 KB Output is correct
56 Correct 16 ms 2752 KB Output is correct
57 Correct 23 ms 5808 KB Output is correct
58 Correct 19 ms 4520 KB Output is correct
59 Correct 14 ms 3364 KB Output is correct
60 Correct 10 ms 1456 KB Output is correct
61 Correct 282 ms 6164 KB Output is correct
62 Correct 43 ms 11628 KB Output is correct
63 Correct 42 ms 11568 KB Output is correct
64 Correct 39 ms 11548 KB Output is correct
65 Correct 11 ms 1488 KB Output is correct
66 Correct 1716 ms 11660 KB Output is correct
67 Correct 2184 ms 11260 KB Output is correct
68 Correct 1704 ms 11576 KB Output is correct
69 Correct 935 ms 11596 KB Output is correct
70 Correct 82 ms 11524 KB Output is correct
71 Correct 884 ms 11532 KB Output is correct
72 Correct 1488 ms 11652 KB Output is correct
73 Correct 862 ms 11596 KB Output is correct
74 Correct 18 ms 1356 KB Output is correct
75 Correct 18 ms 1444 KB Output is correct
76 Correct 2169 ms 11616 KB Output is correct
77 Correct 3188 ms 11700 KB Output is correct
78 Execution timed out 4080 ms 11624 KB Time limit exceeded
79 Halted 0 ms 0 KB -