답안 #1056236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056236 2024-08-13T08:21:32 Z tolbi 송신탑 (IOI22_towers) C++17
4 / 100
636 ms 57648 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];
	}
}
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]);
		}
	}
	function<int(int,int)> partition = [&](int l, int r)->int{
		if (l==r) return l;
		int ele = hsh[-query(l,r)];
		tree[ele].clear();
		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]);
		}
	}
}

int max_towers(int L, int R, int D) {
	vector<int> leafs;
	for (int i = L; i <= R; ++i)
	{
		if (i==L+1) i=R;
		bool isleaf=true;
		assert(tree[i].size()<=2);
		for (auto it : tree[i]){
			if (it>=L && it<=R) isleaf=false;
		}
		if (isleaf) leafs.push_back(i);
	}
	sort(leafs.begin(), leafs.end(), [&](int a, int b){
		return tin[a]<tin[b];
	});
	int curn = leafs[0];
	int sz = 1;
	for (int i = 1; i < leafs.size(); i++){
		int ara = lca(curn,leafs[i]);
		if (max(H[leafs[i]],H[curn]) <= H[ara]-D){
			sz++;
			curn=leafs[i];
		}
		else if (sz==1 && H[curn]>H[leafs[i]]){
			curn=leafs[i];
		}
	}
	return sz;
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |  for (int i = 1; i < leafs.size(); i++){
      |                  ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 24920 KB Output is correct
2 Correct 574 ms 38736 KB Output is correct
3 Correct 602 ms 38992 KB Output is correct
4 Correct 636 ms 39504 KB Output is correct
5 Correct 612 ms 39492 KB Output is correct
6 Correct 610 ms 39392 KB Output is correct
7 Correct 564 ms 39384 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 2 ms 7000 KB Output is correct
10 Correct 2 ms 6996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 13400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 13400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 57648 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 155 ms 10584 KB 1st lines differ - on the 1st token, expected: '7197', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 13400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 24920 KB Output is correct
2 Correct 574 ms 38736 KB Output is correct
3 Correct 602 ms 38992 KB Output is correct
4 Correct 636 ms 39504 KB Output is correct
5 Correct 612 ms 39492 KB Output is correct
6 Correct 610 ms 39392 KB Output is correct
7 Correct 564 ms 39384 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 2 ms 7000 KB Output is correct
10 Correct 2 ms 6996 KB Output is correct
11 Runtime error 5 ms 13400 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -