답안 #1077520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077520 2024-08-27T07:49:42 Z pcc 송신탑 (IOI22_towers) C++17
11 / 100
4000 ms 7688 KB
#include "towers.h"

#include <vector>
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fs first
#define sc second
using namespace std;

const int B = 20;
const int mxn = 1e5+10;
const int inf = 1e9;

int N;
vector<int> H;

int par[mxn][B];
pii tree[mxn];
int arr[mxn];
int rt;
int dep[mxn];
pii big[mxn];
pii eul[mxn];
int dp[mxn];
multiset<int> st[mxn];

void dfs(int now){
	for(int i = 1;i<B;i++)par[now][i] = par[par[now][i-1]][i-1];
	eul[now] = pii(now,now);
	if(tree[now].fs){
		int nxt = tree[now].fs;
		assert(arr[now]>arr[nxt]);
		dep[nxt] = dep[now]+1;
		par[nxt][0] = now;
		dfs(nxt);
		eul[now].fs = eul[nxt].fs;
	}
	if(tree[now].sc){
		int nxt = tree[now].sc;
		assert(arr[now]>arr[nxt]);
		dep[nxt] = dep[now]+1;
		par[nxt][0] = now;
		dfs(nxt);
		eul[now].sc = eul[nxt].sc;
	}
	return;
}

void add(int now,int tar,int val,int D){
	int pos = now;
	for(int i = B-1;i>=0;i--){
		int p = par[now][i];
		if(arr[p]<tar)now = p;
	}
	if(arr[now]<tar)now = par[now][0];
	if(arr[now]<tar)return;
	int side = 0;
	int rs = tree[now].sc;
	if(rs&&eul[rs].fs<=pos&&eul[rs].sc>=pos)side = 1;
	if(!side)big[now].fs = max(big[now].fs,val);
	else big[now].sc = max(big[now].sc,val);
	return;
}

int dfs1(int now,int D){
	st[now].clear();
	big[now].fs = big[now].sc = 0;
	dp[now] = 1;
	if(!tree[now].fs&&!tree[now].sc)st[now].insert(arr[now]);
	if(tree[now].fs){
		int nxt = tree[now].fs;
		dfs1(nxt,D);
		dp[now] = max({dp[now],(int)st[nxt].size(),dp[nxt]});
		while(!st[nxt].empty()&&*st[nxt].rbegin()+D)st[nxt].erase(st[nxt].find(*st[nxt].rbegin()));
		if(st[now].size()<st[nxt].size())st[now].swap(st[nxt]);
		for(auto &i:st[nxt])st[now].insert(i);
	}
	if(tree[now].sc){
		int nxt = tree[now].fs;
		dfs1(nxt,D);
		dp[now] = max({dp[now],(int)st[nxt].size(),dp[nxt]});
		while(!st[nxt].empty()&&*st[nxt].rbegin()+D<arr[now])st[nxt].erase(st[nxt].find(*st[nxt].rbegin()));
		if(st[now].size()<st[nxt].size())st[now].swap(st[nxt]);
		for(auto &i:st[nxt])st[now].insert(i);
	}
	cerr<<now<<":";for(auto &j:st[now])cerr<<j<<',';cerr<<endl;
	dp[now] = max(dp[now],(int)st[now].size());
	return dp[now];
}

void build(int s,int e){
	for(auto &i:tree)i = pii(0,0);
	vector<int> st;
	for(int i = s;i<=e;i++){
		while(!st.empty()&&arr[st.back()]<arr[i]){
			tree[i].fs = st.back();
			st.pop_back();
		}
		if(!st.empty())tree[st.back()].sc = i;
		st.push_back(i);
	}
	rt = st[0];
	par[rt][0] = rt;
	dfs(rt);
}

void init(int NN, std::vector<int> HH) {
	N = NN;
	arr[0] = inf;
	for(int i = 0;i<N;i++)arr[i+1] = HH[i];
}

int max_towers(int L, int R, int D) {
	L++,R++;
	vector<pii> v;
	for(int i = L;i<=R;i++){
		pii rng = pii(i,i);
		for(int j = i-1;j>=1;j--){
			if(arr[j]>=arr[i]+D)break;
			rng.fs = j;
		}
		for(int j = i+1;j<=N;j++){
			if(arr[j]>=arr[i]+D)break;
			rng.sc = j;
		}
		v.push_back(rng);
	}
	sort(v.rbegin(),v.rend());
	int lp = N+1;
	int ans = 0;
	for(auto &[l,r]:v){
		if(r<lp)ans++,lp = l;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4067 ms 6236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 5172 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4980 KB Output is correct
9 Correct 2 ms 4920 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 4 ms 4952 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 4 ms 4952 KB Output is correct
27 Correct 3 ms 5196 KB Output is correct
28 Correct 4 ms 4952 KB Output is correct
29 Correct 3 ms 4952 KB Output is correct
30 Correct 4 ms 4952 KB Output is correct
31 Correct 4 ms 4952 KB Output is correct
32 Correct 4 ms 4952 KB Output is correct
33 Correct 5 ms 4952 KB Output is correct
34 Correct 5 ms 5116 KB Output is correct
35 Correct 4 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 5172 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4980 KB Output is correct
9 Correct 2 ms 4920 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 4 ms 4952 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 4 ms 4952 KB Output is correct
27 Correct 3 ms 5196 KB Output is correct
28 Correct 4 ms 4952 KB Output is correct
29 Correct 3 ms 4952 KB Output is correct
30 Correct 4 ms 4952 KB Output is correct
31 Correct 4 ms 4952 KB Output is correct
32 Correct 4 ms 4952 KB Output is correct
33 Correct 5 ms 4952 KB Output is correct
34 Correct 5 ms 5116 KB Output is correct
35 Correct 4 ms 4952 KB Output is correct
36 Correct 59 ms 5968 KB Output is correct
37 Correct 1359 ms 6596 KB Output is correct
38 Correct 258 ms 6232 KB Output is correct
39 Correct 1876 ms 6344 KB Output is correct
40 Correct 217 ms 6232 KB Output is correct
41 Correct 2248 ms 7368 KB Output is correct
42 Correct 18 ms 6232 KB Output is correct
43 Correct 2069 ms 6600 KB Output is correct
44 Correct 576 ms 6232 KB Output is correct
45 Correct 170 ms 6232 KB Output is correct
46 Correct 71 ms 6232 KB Output is correct
47 Correct 14 ms 6608 KB Output is correct
48 Correct 12 ms 6352 KB Output is correct
49 Correct 12 ms 6232 KB Output is correct
50 Correct 1151 ms 6232 KB Output is correct
51 Correct 1258 ms 6596 KB Output is correct
52 Correct 19 ms 7376 KB Output is correct
53 Correct 17 ms 7376 KB Output is correct
54 Correct 17 ms 7376 KB Output is correct
55 Correct 3374 ms 7460 KB Output is correct
56 Correct 1926 ms 7368 KB Output is correct
57 Correct 3199 ms 7380 KB Output is correct
58 Correct 2413 ms 7368 KB Output is correct
59 Correct 1429 ms 7312 KB Output is correct
60 Correct 76 ms 7368 KB Output is correct
61 Correct 1304 ms 7296 KB Output is correct
62 Correct 2276 ms 7368 KB Output is correct
63 Correct 1220 ms 7440 KB Output is correct
64 Execution timed out 4030 ms 7252 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4074 ms 7688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4058 ms 5760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 5172 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4980 KB Output is correct
9 Correct 2 ms 4920 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 4 ms 4952 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 4 ms 4952 KB Output is correct
27 Correct 3 ms 5196 KB Output is correct
28 Correct 4 ms 4952 KB Output is correct
29 Correct 3 ms 4952 KB Output is correct
30 Correct 4 ms 4952 KB Output is correct
31 Correct 4 ms 4952 KB Output is correct
32 Correct 4 ms 4952 KB Output is correct
33 Correct 5 ms 4952 KB Output is correct
34 Correct 5 ms 5116 KB Output is correct
35 Correct 4 ms 4952 KB Output is correct
36 Correct 59 ms 5968 KB Output is correct
37 Correct 1359 ms 6596 KB Output is correct
38 Correct 258 ms 6232 KB Output is correct
39 Correct 1876 ms 6344 KB Output is correct
40 Correct 217 ms 6232 KB Output is correct
41 Correct 2248 ms 7368 KB Output is correct
42 Correct 18 ms 6232 KB Output is correct
43 Correct 2069 ms 6600 KB Output is correct
44 Correct 576 ms 6232 KB Output is correct
45 Correct 170 ms 6232 KB Output is correct
46 Correct 71 ms 6232 KB Output is correct
47 Correct 14 ms 6608 KB Output is correct
48 Correct 12 ms 6352 KB Output is correct
49 Correct 12 ms 6232 KB Output is correct
50 Correct 1151 ms 6232 KB Output is correct
51 Correct 1258 ms 6596 KB Output is correct
52 Correct 19 ms 7376 KB Output is correct
53 Correct 17 ms 7376 KB Output is correct
54 Correct 17 ms 7376 KB Output is correct
55 Correct 3374 ms 7460 KB Output is correct
56 Correct 1926 ms 7368 KB Output is correct
57 Correct 3199 ms 7380 KB Output is correct
58 Correct 2413 ms 7368 KB Output is correct
59 Correct 1429 ms 7312 KB Output is correct
60 Correct 76 ms 7368 KB Output is correct
61 Correct 1304 ms 7296 KB Output is correct
62 Correct 2276 ms 7368 KB Output is correct
63 Correct 1220 ms 7440 KB Output is correct
64 Execution timed out 4030 ms 7252 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4067 ms 6236 KB Time limit exceeded
2 Halted 0 ms 0 KB -