답안 #1056393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056393 2024-08-13T09:12:33 Z tolbi 송신탑 (IOI22_towers) C++17
0 / 100
63 ms 29292 KB
#include "towers.h"

#include <bits/stdc++.h>
using namespace std;
#define tol(bi) ((1LL)<<((int)(bi)))
constexpr int MAXN = 1e5;
constexpr int LOG = 20;
int st[MAXN*4][LOG], tin[MAXN], rev[MAXN*4];
vector<int> tree[MAXN];
map<int,int> hsh;
vector<int> H;
int query(int l, int r){
	int ara = r-l+1;
	int lg = log2(ara);
	return min(st[l][lg],st[r-tol(lg)+1][lg]);
}
int lca(int a, int b){
	if (tin[a]>tin[b]) swap(a,b);
	return rev[query(tin[a],tin[b])];
}
int ind;
void dfs(int node){
	st[ind][0]=ind;
	rev[ind]=node;
	tin[node]=ind++;
	for (auto it : tree[node]){
		dfs(it);
		st[ind++][0]=tin[node];
	}
}
vector<int> leafs;
void init(int N, std::vector<int> H) {
	::H=H;
	ind=0;
	for (int i = 0; i < N; i++){
		hsh[H[i]]=i;
		st[i][0]=-H[i];
	}
	for (int j = 1; j < LOG; j++){
		for (int i = 0; i < N; i++){
			st[i][j]=1;
			if (st[i][j-1]==1 || i+tol(j-1)>=N) continue;
			st[i][j]=min(st[i][j-1],st[i+tol(j-1)][j-1]);
		}
	}
	for (int i = 0; i < N; ++i)
	{
		tree[i].clear();
	}
	function<int(int,int)> partition = [&](int l, int r)->int{
		if (l==r) return l;
		int ele = hsh[-query(l,r)];
		if (l<=ele-1) tree[ele].push_back(partition(l,ele-1));
		if (ele+1<=r) tree[ele].push_back(partition(ele+1,r));
		return ele;
	};
	int root = partition(0,N-1);
	dfs(root);
	for (int j = 1; j < LOG; j++){
		for (int i = 0; i < ind; i++){
			st[i][j]=-1;
			if (st[i][j-1]==-1 || i+tol(j-1)>=ind) continue;
			st[i][j]=min(st[i][j-1],st[i+tol(j-1)][j-1]);
		}
	}
	for (int i = 0; i < N; ++i)
	{
		if (tree[i].size()==0) leafs.push_back(i);
	}
}

int max_towers(int L, int R, int D) {
	if (L==R) return 1;
	auto ub = lower_bound(leafs.begin(), leafs.end(), R+1);
	auto lb = lower_bound(leafs.begin(), leafs.end(), L);
	int ans = ub-lb;
	cout<<((ub==leafs.end())?(-1):(*ub))<<endl;
	cout<<((lb==leafs.end())?(-1):(*lb))<<endl;
	cout<<ans<<endl;
	if (ub==leafs.begin() || *(ub-1) != R){
			int i = R;
			bool isleaf=true;
			for (auto it : tree[i]){
				if (it<i) isleaf=false;
			}
			if (isleaf) ans++;
	}
	if (lb==leafs.end() || *lb != L){
		int i = L;
		bool isleaf=true;
		for (auto it : tree[i]){
			if (it>i) isleaf=false;
		}
		if (isleaf) ans++;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 23900 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6744 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6744 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 29292 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 10712 KB Token parameter [name=secret] equals to "-1", doesn't correspond to pattern "[0-9a-zA-Z]{1,64}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6744 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 23900 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -