Submission #835076

# Submission time Handle Problem Language Result Execution time Memory
835076 2023-08-23T07:40:35 Z ttamx Radio Towers (IOI22_towers) C++17
17 / 100
1033 ms 112004 KB
#include "towers.h"
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> p2;

const int N=1e5+5;
const int K=1<<18;
const int LG=17;
const int inf=2e9;

int n;
int h[N],spmx[LG][N],spmn[LG][N];
vector<pair<int,int>> vec;

struct persist{
	struct info{
		int mn,mx,val;
		info():mn(inf),mx(-inf),val(0){}
		info(int x):mn(x),mx(x),val(1){}
		friend info operator+(info a,info b){
			info c;
			c.mn=min(a.mn,b.mn);
			c.mx=max(a.mx,b.mx);
			c.val=a.val+b.val;
			return c;
		}
	};
	struct node;
	typedef node* pnode;
	struct node{
		info val;
		pnode l,r;
		node():val(),l(nullptr),r(nullptr){}
	};
	pnode rt[N];
	void build(int l,int r,pnode &t){
		t=new node();
		if(l==r)return;
		int m=(l+r)/2;
		build(l,m,t->l);
		build(m+1,r,t->r);
	}
	void build(int t){
		build(1,n,rt[t]);
	}
	void update(int l,int r,pnode &t,pnode k,int x){
		t=new node(*k);
		t->val=t->val+info(x);
		if(l==r)return;
		int m=(l+r)/2;
		if(x<=m)update(l,m,t->l,k->l,x);
		else update(m+1,r,t->r,k->r,x);
	}
	void update(int k,int t,int x){
		update(1,n,rt[t],rt[k],x);
	}
	info query(int l,int r,pnode t,int x,int y){
		if(y<l||r<x)return info();
		if(x<=l&&r<=y)return t->val;
		int m=(l+r)/2;
		return query(l,m,t->l,x,y)+query(m+1,r,t->r,x,y);
	}
	info query(int t,int x,int y){
		return query(1,n,rt[t],x,y);
	}
}pst;

struct segtree{
	struct node{
		int mn,mx,vl,vr;
		node(int x=0):mn(x),mx(x),vl(0),vr(0){}
		friend node operator+(node a,node b){
			node c;
			c.mn=min(a.mn,b.mn);
			c.mx=max(a.mx,b.mx);
			c.vl=max({a.vl,b.vl,b.mx-a.mn});
			c.vr=max({a.vr,b.vr,a.mx-b.mn});
			return c;
		}
	}t[K];
	void build(int l,int r,int i){
		if(l==r)return void(t[i]=node(h[l]));
		int m=(l+r)/2;
		build(l,m,i*2);
		build(m+1,r,i*2+1);
		t[i]=t[i*2]+t[i*2+1];
	}
	void build(){
		build(1,n,1);
	}
	node query(int l,int r,int i,int x,int y){
		if(x<=l&&r<=y)return t[i];
		int m=(l+r)/2;
		if(y<=m)return query(l,m,i*2,x,y);
		if(m<x)return query(m+1,r,i*2+1,x,y);
		return query(l,m,i*2,x,y)+query(m+1,r,i*2+1,x,y);
	}
	node query(int x,int y){
		return query(1,n,1,x,y);
	}
}s;

int rmxq(int l,int r){
	int k=31-__builtin_clz(r-l+1);
	return max(spmx[k][l],spmx[k][r-(1<<k)+1]);
}

int rmnq(int l,int r){
	int k=31-__builtin_clz(r-l+1);
	return min(spmn[k][l],spmn[k][r-(1<<k)+1]);
}

void init(int N,vector<int> H){
	n=N;
	for(int i=1;i<=n;i++)h[i]=H[i-1];
	h[0]=h[n+1]=inf;
	for(int i=0;i<=n+1;i++)spmx[0][i]=spmn[0][i]=h[i];
	for(int i=1;i<LG;i++){
		for(int j=0;j+(1<<i)-1<=n+1;j++){
			spmx[i][j]=max(spmx[i-1][j],spmx[i-1][j+(1<<(i-1))]);
			spmn[i][j]=min(spmn[i-1][j],spmn[i-1][j+(1<<(i-1))]);
		}
	}
	auto lb=[&](int id){
		int l=0,r=id-1;
		while(l<r){
			int m=(l+r+1)/2;
			if(rmnq(m,id)<h[id])l=m;
			else r=m-1;
		}
		return l;
	};
	auto ub=[&](int id){
		int l=id+1,r=n+1;
		while(l<r){
			int m=(l+r)/2;
			if(rmnq(id,m)<h[id])r=m;
			else l=m+1;
		}
		return l;
	};
	for(int i=1;i<=n;i++){
		int l=lb(i),r=ub(i);
		int d=min(rmxq(l,i),rmxq(i,r))-h[i];
		vec.emplace_back(d,i);
	}
	vec.emplace_back(-inf,-1);
	sort(vec.begin(),vec.end());
	pst.build(n+1);
	for(int i=n;i>=1;i--){
		pst.update(i+1,i,vec[i].second);
	}
	s.build();
}

int max_towers(int L,int R,int D){
	L++,R++;
	auto lb=[&](int id){
		int l=L-1,r=id-1;
		while(l<r){
			int m=(l+r+1)/2;
			if(rmxq(m,id)>=h[id]+D)l=m;
			else r=m-1;
		}
		return l;
	};
	auto ub=[&](int id){
		int l=id+1,r=R+1;
		while(l<r){
			int m=(l+r)/2;
			if(rmxq(id,m)>=h[id]+D)r=m;
			else l=m+1;
		}
		return l;
	};
	int ver=lower_bound(vec.begin(),vec.end(),p2(D,0))-vec.begin();
	auto res=pst.query(ver,L,R);
	if(res.val==0)return 1;
	int l=lb(res.mn),r=ub(res.mx),ans=res.val;
	if(L<=l&&s.query(L,l).vl>=D)ans++;
	if(r<=R&&s.query(r,R).vr>=D)ans++;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 417 ms 66024 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4688 KB Output is correct
2 Correct 3 ms 5968 KB Output is correct
3 Correct 3 ms 5968 KB Output is correct
4 Correct 3 ms 5968 KB Output is correct
5 Correct 3 ms 5968 KB Output is correct
6 Correct 4 ms 5968 KB Output is correct
7 Correct 4 ms 5968 KB Output is correct
8 Correct 4 ms 5968 KB Output is correct
9 Correct 3 ms 5968 KB Output is correct
10 Correct 3 ms 5968 KB Output is correct
11 Correct 3 ms 5968 KB Output is correct
12 Incorrect 2 ms 4372 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4688 KB Output is correct
2 Correct 3 ms 5968 KB Output is correct
3 Correct 3 ms 5968 KB Output is correct
4 Correct 3 ms 5968 KB Output is correct
5 Correct 3 ms 5968 KB Output is correct
6 Correct 4 ms 5968 KB Output is correct
7 Correct 4 ms 5968 KB Output is correct
8 Correct 4 ms 5968 KB Output is correct
9 Correct 3 ms 5968 KB Output is correct
10 Correct 3 ms 5968 KB Output is correct
11 Correct 3 ms 5968 KB Output is correct
12 Incorrect 2 ms 4372 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 741 ms 111136 KB Output is correct
2 Correct 882 ms 111856 KB Output is correct
3 Correct 952 ms 111924 KB Output is correct
4 Correct 855 ms 111924 KB Output is correct
5 Correct 1031 ms 111892 KB Output is correct
6 Correct 908 ms 111964 KB Output is correct
7 Correct 1033 ms 111840 KB Output is correct
8 Correct 790 ms 111840 KB Output is correct
9 Correct 784 ms 111928 KB Output is correct
10 Correct 848 ms 111932 KB Output is correct
11 Correct 952 ms 111864 KB Output is correct
12 Incorrect 844 ms 111900 KB 170th lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 281 ms 27424 KB Output is correct
2 Correct 884 ms 111840 KB Output is correct
3 Correct 867 ms 111960 KB Output is correct
4 Correct 922 ms 111956 KB Output is correct
5 Correct 868 ms 111932 KB Output is correct
6 Correct 754 ms 111936 KB Output is correct
7 Correct 811 ms 111852 KB Output is correct
8 Correct 666 ms 111932 KB Output is correct
9 Correct 777 ms 111940 KB Output is correct
10 Correct 851 ms 111908 KB Output is correct
11 Correct 674 ms 111852 KB Output is correct
12 Correct 120 ms 112004 KB Output is correct
13 Correct 125 ms 111908 KB Output is correct
14 Correct 126 ms 111936 KB Output is correct
15 Correct 107 ms 111956 KB Output is correct
16 Correct 111 ms 111936 KB Output is correct
17 Correct 114 ms 108160 KB Output is correct
18 Correct 123 ms 111952 KB Output is correct
19 Correct 119 ms 111932 KB Output is correct
20 Correct 125 ms 111920 KB Output is correct
21 Correct 148 ms 111944 KB Output is correct
22 Correct 129 ms 111960 KB Output is correct
23 Correct 128 ms 111904 KB Output is correct
24 Correct 102 ms 111932 KB Output is correct
25 Correct 108 ms 111860 KB Output is correct
26 Correct 114 ms 111924 KB Output is correct
27 Correct 117 ms 111968 KB Output is correct
28 Correct 3 ms 5968 KB Output is correct
29 Correct 3 ms 5968 KB Output is correct
30 Correct 3 ms 5968 KB Output is correct
31 Correct 4 ms 5968 KB Output is correct
32 Correct 4 ms 5968 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 4 ms 5996 KB Output is correct
35 Correct 4 ms 5968 KB Output is correct
36 Correct 4 ms 5968 KB Output is correct
37 Correct 3 ms 5968 KB Output is correct
38 Correct 3 ms 5968 KB Output is correct
39 Correct 3 ms 5968 KB Output is correct
40 Correct 3 ms 5968 KB Output is correct
41 Correct 3 ms 5968 KB Output is correct
42 Correct 4 ms 5968 KB Output is correct
43 Correct 4 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4688 KB Output is correct
2 Correct 3 ms 5968 KB Output is correct
3 Correct 3 ms 5968 KB Output is correct
4 Correct 3 ms 5968 KB Output is correct
5 Correct 3 ms 5968 KB Output is correct
6 Correct 4 ms 5968 KB Output is correct
7 Correct 4 ms 5968 KB Output is correct
8 Correct 4 ms 5968 KB Output is correct
9 Correct 3 ms 5968 KB Output is correct
10 Correct 3 ms 5968 KB Output is correct
11 Correct 3 ms 5968 KB Output is correct
12 Incorrect 2 ms 4372 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 417 ms 66024 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -