답안 #410591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410591 2021-05-23T05:56:27 Z Jasiekstrz Pyramid Base (IOI08_pyramid_base) C++17
80 / 100
5000 ms 36060 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=4e5;
const int P=11e5;
struct Rec
{
	int x1,x2,y1,y2;
	int val;
};
bool comp(Rec &a,Rec &b)
{
	return a.x1<b.x1;
}
Rec tab[N+10];
int pot;
int tree[2*P+10];
int upd[2*P+10];
void pushdown0(int i)
{
	for(int it:{2*i,2*i+1})
	{
		tree[it]=max(tree[it],upd[i]);
		upd[it]=max(upd[it],upd[i]);
	}
	upd[i]=0;
	return;
}
void add0(int i,int l,int r,int ls,int rs,int c)
{
	if(r<ls || rs<l)
		return;
	else if(ls<=l && r<=rs)
	{
		tree[i]=max(tree[i],c);
		upd[i]=max(upd[i],c);
		return;
	}
	pushdown0(i);
	int mid=(l+r)/2;
	add0(2*i,l,mid,ls,rs,c);
	add0(2*i+1,mid+1,r,ls,rs,c);
	tree[i]=min(tree[2*i],tree[2*i+1]);
	return;
}
bool check0(int m,int n,int p,int d)
{
	for(int i=1;i<=n-d+1;i++)
		tree[pot+i-1]=1;
	for(int i=n-d+2;i<=pot;i++)
		tree[pot+i-1]=m+1;
	for(int i=pot-1;i>=1;i--)
		tree[i]=min(tree[2*i],tree[2*i+1]);
	for(int i=1;i<2*pot;i++)
		upd[i]=0;
	for(int i=1,it=1;i<=m;i++)
	{
		while(it<=p && tab[it].x1<=i)
		{
			//cerr<<i<<": "<<tab[it].x1<<" "<<tab[it].x2<<" "<<tab[it].y1<<" "<<tab[it].y2<<"\n";
			add0(1,1,pot,max(1,tab[it].y1-d+1),tab[it].y2,tab[it].x2+1);
			it++;
		}
		if(i-tree[1]+1>=d)
		{
			//cerr<<i<<" "<<tree[1]<<"\n";
			return true;
		}
	}
	return false;
}
int solve0(int m,int n,int p)
{
	sort(tab+1,tab+p+1,comp);
	for(pot=1;pot<=n;pot*=2);
	//cerr<<check0(m,n,p,6)<<"\n";
	//return 0;
	int bg=0,en=min(n,m);
	while(bg<en)
	{
		int mid=(bg+en+1)/2;
		if(check0(m,n,p,mid))
			bg=mid;
		else
			en=mid-1;
	}
	return bg;
}
Rec ev1[2*N+10];
void pushdown1(int i)
{
	for(int it:{2*i,2*i+1})
	{
		tree[it]+=upd[i];
		upd[it]+=upd[i];
	}
	upd[i]=0;
	return;
}
void add1(int i,int l,int r,int ls,int rs,int c)
{
	if(r<ls || rs<l)
		return;
	else if(ls<=l && r<=rs)
	{
		tree[i]+=c;
		upd[i]+=c;
		return;
	}
	pushdown1(i);
	int mid=(l+r)/2;
	add1(2*i,l,mid,ls,rs,c);
	add1(2*i+1,mid+1,r,ls,rs,c);
	tree[i]=min(tree[2*i],tree[2*i+1]);
	return;
}
bool check1(int m,int n,int b,int p,int d)
{
	for(int i=1;i<=p;i++)
	{
		ev1[2*i-1]=ev1[2*i]=tab[i];
		ev1[2*i-1].x2=0;
		ev1[2*i].x1=ev1[2*i].x2+d; ev1[2*i].x2=1;
	}
	sort(ev1+1,ev1+2*p+1,comp);
	for(int i=1;i<=n-d+1;i++)
		tree[pot+i-1]=0;
	for(int i=n-d+2;i<=pot;i++)
		tree[pot+i-1]=b+1;
	for(int i=pot-1;i>=1;i--)
		tree[i]=min(tree[2*i],tree[2*i+1]);
	for(int i=1;i<2*pot;i++)
		upd[i]=0;
	for(int i=1,it=1;i<=m;i++)
	{
		while(it<=2*p && ev1[it].x1<=i)
		{
			if(ev1[it].x2==0)
				add1(1,1,pot,max(1,ev1[it].y1-d+1),ev1[it].y2,ev1[it].val);
			else
				add1(1,1,pot,max(1,ev1[it].y1-d+1),ev1[it].y2,-ev1[it].val);
			it++;
		}
		if(d<=i && tree[1]<=b)
		{
			//cerr<<i<<" "<<tree[1]<<"\n";
			return true;
		}
	}
	return false;
}
int solve1(int m,int n,int b,int p)
{
	for(pot=1;pot<=n;pot*=2);
	int bg=0,en=min(n,m);
	while(bg<en)
	{
		int mid=(bg+en+1)/2;
		if(check1(m,n,b,p,mid))
			bg=mid;
		else
			en=mid-1;
	}
	return bg;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int m,n,b,p;
	cin>>m>>n>>b>>p;
	for(int i=1;i<=p;i++)
		cin>>tab[i].x1>>tab[i].y1>>tab[i].x2>>tab[i].y2>>tab[i].val;
	if(b==0)
		cout<<solve0(m,n,p)<<"\n";
	else
		cout<<solve1(m,n,b,p)<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 16784 KB Output is correct
2 Correct 114 ms 16784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 16716 KB Output is correct
2 Correct 131 ms 16696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 1000 KB Output is correct
2 Correct 73 ms 1000 KB Output is correct
3 Correct 66 ms 964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 241 ms 3524 KB Output is correct
2 Correct 366 ms 3696 KB Output is correct
3 Correct 314 ms 3668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 542 ms 18500 KB Output is correct
2 Correct 50 ms 1868 KB Output is correct
3 Correct 210 ms 18352 KB Output is correct
4 Correct 588 ms 18560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 784 ms 18928 KB Output is correct
2 Correct 1048 ms 18940 KB Output is correct
3 Correct 573 ms 19000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 840 ms 19368 KB Output is correct
2 Correct 1349 ms 19372 KB Output is correct
3 Correct 1296 ms 19368 KB Output is correct
4 Correct 1451 ms 19376 KB Output is correct
5 Correct 1461 ms 19360 KB Output is correct
6 Correct 665 ms 19464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3362 ms 26428 KB Output is correct
2 Correct 474 ms 11480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4988 ms 31264 KB Output is correct
2 Execution timed out 5032 ms 30760 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5076 ms 36060 KB Time limit exceeded
2 Halted 0 ms 0 KB -