Submission #1056395

# Submission time Handle Problem Language Result Execution time Memory
1056395 2024-08-13T09:13:04 Z tolbi Radio Towers (IOI22_towers) C++17
14 / 100
695 ms 37736 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;
	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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 252 ms 24152 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6744 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6744 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 458 ms 29248 KB Output is correct
2 Correct 656 ms 29264 KB Output is correct
3 Correct 635 ms 29264 KB Output is correct
4 Correct 611 ms 28876 KB Output is correct
5 Correct 632 ms 28764 KB Output is correct
6 Correct 620 ms 28876 KB Output is correct
7 Correct 695 ms 28876 KB Output is correct
8 Correct 623 ms 37712 KB Output is correct
9 Correct 603 ms 37712 KB Output is correct
10 Correct 580 ms 35824 KB Output is correct
11 Correct 594 ms 35960 KB Output is correct
12 Correct 542 ms 37716 KB Output is correct
13 Correct 557 ms 37712 KB Output is correct
14 Correct 1 ms 6744 KB Output is correct
15 Correct 1 ms 7000 KB Output is correct
16 Correct 1 ms 7000 KB Output is correct
17 Correct 58 ms 29288 KB Output is correct
18 Correct 54 ms 28872 KB Output is correct
19 Correct 53 ms 28880 KB Output is correct
20 Correct 58 ms 37724 KB Output is correct
21 Correct 47 ms 37532 KB Output is correct
22 Correct 60 ms 29260 KB Output is correct
23 Correct 53 ms 28872 KB Output is correct
24 Correct 53 ms 28876 KB Output is correct
25 Correct 45 ms 37736 KB Output is correct
26 Correct 45 ms 37200 KB Output is correct
27 Correct 2 ms 6744 KB Output is correct
28 Correct 1 ms 6744 KB Output is correct
29 Correct 1 ms 6744 KB Output is correct
30 Correct 1 ms 7000 KB Output is correct
31 Correct 1 ms 7000 KB Output is correct
32 Correct 1 ms 6744 KB Output is correct
33 Correct 2 ms 6744 KB Output is correct
34 Correct 1 ms 6744 KB Output is correct
35 Correct 1 ms 7000 KB Output is correct
36 Correct 2 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 10584 KB 1st lines differ - on the 1st token, expected: '7197', found: '8004'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6744 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 252 ms 24152 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -