답안 #835075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835075 2023-08-23T07:38:24 Z ttamx 송신탑 (IOI22_towers) C++17
17 / 100
985 ms 112116 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++;
	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=res.mn,r=res.mx,ans=res.val;
	if(s.query(L,l).vl>=D)ans++;
	if(s.query(r,R).vr>=D)ans++;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 349 ms 65984 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 5980 KB Output is correct
5 Correct 3 ms 5968 KB Output is correct
6 Correct 4 ms 5968 KB Output is correct
7 Correct 3 ms 5968 KB Output is correct
8 Correct 3 ms 5956 KB Output is correct
9 Correct 4 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 4432 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 5980 KB Output is correct
5 Correct 3 ms 5968 KB Output is correct
6 Correct 4 ms 5968 KB Output is correct
7 Correct 3 ms 5968 KB Output is correct
8 Correct 3 ms 5956 KB Output is correct
9 Correct 4 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 4432 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 732 ms 111160 KB Output is correct
2 Correct 985 ms 111932 KB Output is correct
3 Correct 935 ms 111876 KB Output is correct
4 Correct 829 ms 111932 KB Output is correct
5 Correct 875 ms 111888 KB Output is correct
6 Correct 920 ms 111920 KB Output is correct
7 Correct 928 ms 112116 KB Output is correct
8 Correct 866 ms 111884 KB Output is correct
9 Correct 946 ms 111868 KB Output is correct
10 Correct 874 ms 111916 KB Output is correct
11 Correct 847 ms 111876 KB Output is correct
12 Incorrect 908 ms 111904 KB 170th lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 27468 KB Output is correct
2 Correct 830 ms 112052 KB Output is correct
3 Correct 865 ms 111940 KB Output is correct
4 Correct 880 ms 111944 KB Output is correct
5 Correct 805 ms 111872 KB Output is correct
6 Correct 717 ms 111916 KB Output is correct
7 Correct 788 ms 111960 KB Output is correct
8 Correct 764 ms 111920 KB Output is correct
9 Correct 687 ms 111944 KB Output is correct
10 Correct 866 ms 111888 KB Output is correct
11 Correct 604 ms 111844 KB Output is correct
12 Correct 122 ms 111860 KB Output is correct
13 Correct 127 ms 111876 KB Output is correct
14 Correct 129 ms 111952 KB Output is correct
15 Correct 109 ms 111912 KB Output is correct
16 Correct 118 ms 111928 KB Output is correct
17 Correct 130 ms 108148 KB Output is correct
18 Correct 128 ms 111932 KB Output is correct
19 Correct 127 ms 111880 KB Output is correct
20 Correct 130 ms 111864 KB Output is correct
21 Correct 133 ms 111908 KB Output is correct
22 Correct 127 ms 111892 KB Output is correct
23 Correct 129 ms 111868 KB Output is correct
24 Correct 111 ms 111924 KB Output is correct
25 Correct 119 ms 112036 KB Output is correct
26 Correct 106 ms 111896 KB Output is correct
27 Correct 109 ms 111876 KB Output is correct
28 Correct 4 ms 5968 KB Output is correct
29 Correct 3 ms 5968 KB Output is correct
30 Correct 4 ms 5980 KB Output is correct
31 Correct 3 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 3 ms 5968 KB Output is correct
35 Correct 3 ms 5968 KB Output is correct
36 Correct 4 ms 5920 KB Output is correct
37 Correct 3 ms 5968 KB Output is correct
38 Correct 4 ms 5968 KB Output is correct
39 Correct 3 ms 5968 KB Output is correct
40 Correct 4 ms 5932 KB Output is correct
41 Correct 4 ms 5992 KB Output is correct
42 Correct 3 ms 5968 KB Output is correct
43 Correct 3 ms 5968 KB Output is correct
# 결과 실행 시간 메모리 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 5980 KB Output is correct
5 Correct 3 ms 5968 KB Output is correct
6 Correct 4 ms 5968 KB Output is correct
7 Correct 3 ms 5968 KB Output is correct
8 Correct 3 ms 5956 KB Output is correct
9 Correct 4 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 4432 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 349 ms 65984 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -