답안 #626330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626330 2022-08-11T11:47:19 Z PoPularPlusPlus 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 9144 KB
#include "towers.h"

#include <bits/stdc++.h>

using namespace std;

#define vf first
#define vs second
#define mp(x,y) make_pair(x,y)

struct Seg {
	int siz = 1;
	vector<int> sums;
	void init(int n){
		while(siz < n)siz*=2;
		
		sums.assign(siz * 2, 0LL);
	}
	
	void set(int i , int v , int x , int lx , int rx){
		if(rx - lx ==1){
			sums[x] = v;
			return;
		}
		int m = (lx + rx) / 2;
		if(i < m){
			set(i , v , 2 * x + 1 , lx , m);
		}
		else {
			set(i , v , 2 * x + 2 , m , rx);
		}
		sums[x]=max(sums[2 * x + 1] , sums[2 * x + 2]);
	}
	
	void set(int x , int y){
		set(x  ,y , 0 , 0 , siz);
	}
	
	int sum(int l , int r , int x , int lx , int rx){
		if(lx >= l && rx <= r){
			return sums[x];
		}
		if(lx >= r || rx <= l)return 0;
		int m = (lx + rx) / 2;
		return max(sum(l , r , 2 * x + 1 , lx , m) , sum(l , r , 2 * x + 2 , m , rx));
	}
	
	int sum(int l , int r){
		return sum(l , r , 0 , 0 , siz);
	}
	
};


vector<int> arr;

void init(int n, std::vector<int> h) {
	arr = h;
}

int max_towers(int l , int r , int d) {
	Seg st;
	int n = arr.size();
	st.init(n+1);
	set<pair<int,int>> s;
	int dp[n];
	int left[n];
	for(int i = n - 1; i >= 0; i--){
		while(s.size() && (*(s.begin())).vf <= arr[i] - d){
			left[(*(s.begin())).vs] = i;
			s.erase(s.begin());
		}
		s.insert(mp(arr[i] , i));
	}
	while(s.size()){
		left[(*(s.begin())).vs] = -1;
		s.erase(s.begin());
	}
	set<pair<int,pair<int,int>>> s1;
	//for(int i = 0; i < n; i++)cout << left[i] << ' ';
	memset(dp,0,sizeof dp);
	for(int i = l; i <= r; i++){
		dp[i] = 1;
		while(s1.size() && (*(s1.begin())).vf <= arr[i] - d){
			int pos = (*(s1.begin())).vs.vs;
			dp[pos] = max(dp[pos] , (*(s1.begin())).vs.vf);
			st.set(pos , dp[pos]);
			s1.erase(s1.begin());
		}
		if(i > 0)dp[i] = max(dp[i] , dp[i-1]);
		int cur = 1;
		int p = left[i];
		if(p >= l){
			cur += st.sum(l , p);
		}
		s1.insert(mp(arr[i] , mp(cur , i)));
	}
	while(s1.size()){
		int pos = (*(s1.begin())).vs.vs;
		dp[pos] = max(dp[pos] , (*(s1.begin())).vs.vf);
		s1.erase(s1.begin());
	}
	int ans = 0;
	for(int i = l; i <= r; i++)ans = max(ans , dp[i]);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4025 ms 5104 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 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 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 464 KB Output is correct
24 Correct 1 ms 336 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 1 ms 336 KB Output is correct
29 Correct 2 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 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 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 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 464 KB Output is correct
24 Correct 1 ms 336 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 1 ms 336 KB Output is correct
29 Correct 2 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 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 19 ms 2084 KB Output is correct
37 Correct 63 ms 6476 KB Output is correct
38 Correct 38 ms 4416 KB Output is correct
39 Correct 53 ms 7200 KB Output is correct
40 Correct 31 ms 4116 KB Output is correct
41 Correct 59 ms 5528 KB Output is correct
42 Correct 23 ms 2892 KB Output is correct
43 Correct 42 ms 7568 KB Output is correct
44 Correct 30 ms 4104 KB Output is correct
45 Correct 48 ms 7580 KB Output is correct
46 Correct 34 ms 3752 KB Output is correct
47 Correct 41 ms 2856 KB Output is correct
48 Correct 24 ms 2836 KB Output is correct
49 Correct 20 ms 2832 KB Output is correct
50 Correct 31 ms 4112 KB Output is correct
51 Correct 37 ms 7416 KB Output is correct
52 Correct 43 ms 2884 KB Output is correct
53 Correct 51 ms 2836 KB Output is correct
54 Correct 46 ms 2892 KB Output is correct
55 Correct 60 ms 9140 KB Output is correct
56 Correct 47 ms 7152 KB Output is correct
57 Correct 76 ms 6560 KB Output is correct
58 Correct 61 ms 5564 KB Output is correct
59 Correct 60 ms 4380 KB Output is correct
60 Correct 63 ms 2936 KB Output is correct
61 Correct 55 ms 4288 KB Output is correct
62 Correct 58 ms 5424 KB Output is correct
63 Correct 57 ms 4132 KB Output is correct
64 Correct 53 ms 7592 KB Output is correct
65 Correct 54 ms 9144 KB Output is correct
66 Correct 55 ms 6812 KB Output is correct
67 Correct 53 ms 9112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4003 ms 2836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4030 ms 2448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 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 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 464 KB Output is correct
24 Correct 1 ms 336 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 1 ms 336 KB Output is correct
29 Correct 2 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 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 19 ms 2084 KB Output is correct
37 Correct 63 ms 6476 KB Output is correct
38 Correct 38 ms 4416 KB Output is correct
39 Correct 53 ms 7200 KB Output is correct
40 Correct 31 ms 4116 KB Output is correct
41 Correct 59 ms 5528 KB Output is correct
42 Correct 23 ms 2892 KB Output is correct
43 Correct 42 ms 7568 KB Output is correct
44 Correct 30 ms 4104 KB Output is correct
45 Correct 48 ms 7580 KB Output is correct
46 Correct 34 ms 3752 KB Output is correct
47 Correct 41 ms 2856 KB Output is correct
48 Correct 24 ms 2836 KB Output is correct
49 Correct 20 ms 2832 KB Output is correct
50 Correct 31 ms 4112 KB Output is correct
51 Correct 37 ms 7416 KB Output is correct
52 Correct 43 ms 2884 KB Output is correct
53 Correct 51 ms 2836 KB Output is correct
54 Correct 46 ms 2892 KB Output is correct
55 Correct 60 ms 9140 KB Output is correct
56 Correct 47 ms 7152 KB Output is correct
57 Correct 76 ms 6560 KB Output is correct
58 Correct 61 ms 5564 KB Output is correct
59 Correct 60 ms 4380 KB Output is correct
60 Correct 63 ms 2936 KB Output is correct
61 Correct 55 ms 4288 KB Output is correct
62 Correct 58 ms 5424 KB Output is correct
63 Correct 57 ms 4132 KB Output is correct
64 Correct 53 ms 7592 KB Output is correct
65 Correct 54 ms 9144 KB Output is correct
66 Correct 55 ms 6812 KB Output is correct
67 Correct 53 ms 9112 KB Output is correct
68 Execution timed out 4003 ms 2836 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4025 ms 5104 KB Time limit exceeded
2 Halted 0 ms 0 KB -