Submission #421137

# Submission time Handle Problem Language Result Execution time Memory
421137 2021-06-08T18:47:01 Z Pyqe Izvanzemaljci (COI21_izvanzemaljci) C++14
56 / 100
3000 ms 26152 KB
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fr first
#define sc second

const long long ma=1e9,inf=1e18;
long long n,d,nn,nm[2],sk[2][100069];
pair<long long,long long> a[4][100069],as[4][100069],a2[100069];
pair<long long,array<long long,2>> rg[100069];
pair<pair<long long,long long>,long long> ca[3],sq[3];
bitset<100069> vtd;
array<long long,2> a0={-inf,-inf};

struct segtree
{
	long long l,r,lz;
	pair<long long,long long> mxe;
	segtree *p[2];
	
	void bd(long long lh,long long rh)
	{
		l=lh;
		r=rh;
		if(l<r)
		{
			long long ii,md=(l+r)/2;
			
			for(ii=0;ii<2;ii++)
			{
				p[ii]=new segtree;
				p[ii]->bd(!ii?l:md+1,!ii?md:r);
			}
		}
	}
	void rst()
	{
		lz=0;
		if(l==r)
		{
			mxe={-rg[l-1].fr-1,l};
		}
		else
		{
			long long ii;
			
			for(ii=0;ii<2;ii++)
			{
				p[ii]->rst();
			}
			mxe=max(p[0]->mxe,p[1]->mxe);
		}
	}
	void blc()
	{
		long long ii;
		
		for(ii=0;ii<2;ii++)
		{
			p[ii]->mxe.fr+=lz;
			p[ii]->lz+=lz;
		}
		lz=0;
	}
	void ud(long long lh,long long rh,long long w)
	{
		if(l>rh||r<lh);
		else if(l>=lh&&r<=rh)
		{
			mxe.fr+=w;
			lz+=w;
		}
		else
		{
			long long ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ud(lh,rh,w);
			}
			mxe=max(p[0]->mxe,p[1]->mxe);
		}
	}
	pair<long long,long long> qr(long long lh,long long rh)
	{
		if(l>rh||r<lh)
		{
			return {-inf,-1};
		}
		else if(l>=lh&&r<=rh)
		{
			return mxe;
		}
		else
		{
			blc();
			return max(p[0]->qr(lh,rh),p[1]->qr(lh,rh));
		}
	}
}
sg;

int main()
{
	long long i,j,ii,im,u,x,y,x2,y2,k,l,w,p,mn,mx,mn2,lb,rb,lh,rh,md,c=0;
	pair<long long,long long> tmp;
	bool bad;
	
	scanf("%lld%lld",&n,&d);
	for(i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x,&y);
		a[0][i]={x,y};
	}
	for(im=0;im<4;im++)
	{
		sort(a[im]+1,a[im]+n+1);
		for(i=1;i<=n;i++)
		{
			as[im][i]={a[im][i].sc,i};
		}
		sort(as[im]+1,as[im]+n+1);
		if(im<3)
		{
			for(i=1;i<=n;i++)
			{
				x=a[im][i].fr;
				y=a[im][i].sc;
				a[im+1][i]={y,-x};
			}
		}
	}
	sg.bd(1,n);
	for(lh=1,rh=ma*2;lh<=rh;)
	{
		md=(lh+rh)/2;
		bad=0;
		for(im=0;im<4;im++)
		{
			if(d==1)
			{
				if(!im)
				{
					mn=inf;
					mx=-inf;
					mn2=inf;
					for(i=1;i<=n;i++)
					{
						x=a[im][i].fr;
						y=a[im][i].sc;
						mn=min(mn,y);
						mx=max(mx,y);
						if(mx-mn>md||x-a[im][1].fr>md)
						{
							break;
						}
						mn2=mn;
					}
					if(i>n)
					{
						bad=1;
						sq[0]={{a[im][1].fr,mn2},md};
					}
				}
			}
			else if(d==2)
			{
				if(im<2)
				{
					l=0;
					for(ii=0;ii<2;ii++)
					{
						mn=inf;
						mx=-inf;
						k=l;
						mn2=inf;
						for(i=l+1;i<=n;i++)
						{
							x=a[im][i].fr;
							y=a[im][i].sc;
							mn=min(mn,y);
							mx=max(mx,y);
							if(mx-mn>md||x-a[im][l+1].fr>md)
							{
								break;
							}
							if(i==n||x!=a[im][i+1].fr)
							{
								k=i;
								mn2=mn;
							}
						}
						if(!ii)
						{
							ca[ii]={{a[im][k].fr-md,mn2},md};
						}
						else
						{
							ca[ii]={{a[im][l+1].fr,mn2},md};
						}
						l=k;
					}
					if(i>n)
					{
						bad=1;
						for(j=0;j<d;j++)
						{
							sq[j]=ca[j];
						}
					}
				}
			}
			else
			{
				mn=inf;
				mx=-inf;
				k=0;
				mn2=inf;
				vtd.reset();
				for(i=1;i<=n;i++)
				{
					p=as[im][i].sc;
					x=a[im][p].fr;
					y=a[im][p].sc;
					mn=min(mn,x);
					mx=max(mx,x);
					if(mx-mn>md||y-as[im][1].fr>md)
					{
						break;
					}
					if(i==n||y!=as[im][i+1].fr)
					{
						mn2=mn;
						for(;k<i;)
						{
							k++;
							vtd[as[im][k].sc]=1;
						}
					}
				}
				ca[0]={{mn2,as[im][k].fr-md},md};
				nn=0;
				for(i=1;i<=n;i++)
				{
					if(!vtd[i])
					{
						nn++;
						a2[nn]=a[im][i];
					}
				}
				l=0;
				for(ii=0;ii<2;ii++)
				{
					mn=inf;
					mx=-inf;
					k=l;
					mn2=inf;
					for(i=l+1;i<=nn;i++)
					{
						x=a2[i].fr;
						y=a2[i].sc;
						mn=min(mn,y);
						mx=max(mx,y);
						if(mx-mn>md||x-a2[l+1].fr>md)
						{
							break;
						}
						if(i==nn||x!=a2[i+1].fr)
						{
							k=i;
							mn2=mn;
						}
					}
					if(!ii)
					{
						ca[ii+1]={{a2[k].fr-md,mn2},md};
					}
					else
					{
						ca[ii+1]={{a2[l+1].fr,mn2},md};
					}
					l=k;
				}
				if(i>nn)
				{
					bad=1;
					for(j=0;j<d;j++)
					{
						sq[j]=ca[j];
					}
				}
				if(im<2)
				{
					nn=0;
					rg[0].fr=-ma*4;
					for(i=1;i<=n;i++)
					{
						x=a[im][i].fr;
						y=a[im][i].sc;
						if(!nn||x!=rg[nn].fr)
						{
							nn++;
							rg[nn]={x,{y,y}};
						}
						else
						{
							rg[nn].sc[0]=min(rg[nn].sc[0],y);
							rg[nn].sc[1]=max(rg[nn].sc[1],y);
						}
					}
					rg[nn+1].fr=ma*4;
					mn=inf;
					mx=-inf;
					for(i=1;i<=nn;i++)
					{
						x=rg[i].fr;
						y=rg[i].sc[0];
						y2=rg[i].sc[1];
						mn=min(mn,y);
						mx=max(mx,y2);
						if(mx-mn>md||x-rg[1].fr>md)
						{
							break;
						}
					}
					lb=i-1;
					mn=inf;
					mx=-inf;
					for(i=nn;i;i--)
					{
						x=rg[i].fr;
						y=rg[i].sc[0];
						y2=rg[i].sc[1];
						mn=min(mn,y);
						mx=max(mx,y2);
						if(mx-mn>md||rg[nn].fr-x>md)
						{
							break;
						}
					}
					rb=i+1;
					sg.rst();
					for(ii=0;ii<2;ii++)
					{
						nm[ii]=0;
					}
					for(i=1;i<=nn;i++)
					{
						y=rg[i].sc[0];
						y2=rg[i].sc[1];
						for(ii=0;ii<2;ii++)
						{
							u=!ii*2-1;
							for(;nm[ii]&&rg[sk[ii][nm[ii]]].sc[ii]*u>=y*u;nm[ii]--)
							{
								sg.ud(sk[ii][nm[ii]-1]+1,sk[ii][nm[ii]],-abs(y-rg[sk[ii][nm[ii]]].sc[ii]));
							}
							nm[ii]++;
							sk[ii][nm[ii]]=i;
							swap(y,y2);
						}
						sg.ud(i,i,y-y2);
						if(i+1>=rb)
						{
							x2=rg[i+1].fr;
							k=lower_bound(rg+1,rg+nn+1,mp(x2-1-md,a0))-rg;
							l=upper_bound(rg+1,rg+nn+1,mp(x2-2,a0))-rg-1;
							tmp=sg.qr(k+1,min(l,lb+1));
							if(x2-1+tmp.fr>=0)
							{
								lb=tmp.sc-1;
								rb=i+1;
								break;
							}
							tmp=sg.qr(k,min(k,lb+1));
							if(md+tmp.fr+rg[k-1].fr+1>=0)
							{
								lb=k-1;
								rb=i+1;
								break;
							}
						}
					}
					if(i<=nn)
					{
						bad=1;
						mn=inf;
						for(i=1;i<=lb;i++)
						{
							x=rg[i].fr;
							y=rg[i].sc[0];
							mn=min(mn,y);
						}
						sq[0]={{x-md,mn},md};
						mn=inf;
						for(i=nn;i>=rb;i--)
						{
							x=rg[i].fr;
							y=rg[i].sc[0];
							mn=min(mn,y);
						}
						sq[1]={{x,mn},md};
						mn=inf;
						for(i=lb+1;i<rb;i++)
						{
							y=rg[i].sc[0];
							mn=min(mn,y);
						}
						sq[2]={{rg[lb].fr+1,mn},min(rg[rb].fr-rg[lb].fr-2,md)};
					}
				}
			}
			for(i=0;i<d;i++)
			{
				x=sq[i].fr.fr;
				y=sq[i].fr.sc;
				w=sq[i].sc;
				sq[i].fr={y,-x-w};
			}
		}
		if(bad)
		{
			rh=md-1;
		}
		else
		{
			lh=md+1;
		}
	}
	for(i=0;i<d;i++)
	{
		x=sq[i].fr.fr;
		y=sq[i].fr.sc;
		w=sq[i].sc;
		if(x<-ma*3||y<-ma*3||x>ma*3||y>ma*3)
		{
			x=ma*3;
			y=ma*3-c*2;
			w=1;
			c++;
		}
		printf("%lld %lld %lld\n",x,y,w);
	}
}

Compilation message

izvanzemaljci.cpp: In function 'int main()':
izvanzemaljci.cpp:112:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |  scanf("%lld%lld",&n,&d);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
izvanzemaljci.cpp:115:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |   scanf("%lld%lld",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 114 ms 25740 KB Output is correct
8 Correct 114 ms 25636 KB Output is correct
9 Correct 135 ms 25660 KB Output is correct
10 Correct 123 ms 25664 KB Output is correct
11 Correct 118 ms 25648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 120 ms 25836 KB Output is correct
11 Correct 120 ms 25956 KB Output is correct
12 Correct 119 ms 25936 KB Output is correct
13 Correct 121 ms 25856 KB Output is correct
14 Correct 121 ms 26152 KB Output is correct
15 Correct 121 ms 25968 KB Output is correct
16 Correct 117 ms 25916 KB Output is correct
17 Correct 106 ms 23600 KB Output is correct
18 Correct 101 ms 22840 KB Output is correct
19 Correct 94 ms 20784 KB Output is correct
20 Correct 98 ms 22208 KB Output is correct
21 Correct 118 ms 26036 KB Output is correct
22 Correct 117 ms 25796 KB Output is correct
23 Correct 118 ms 25860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 588 KB Output is correct
2 Correct 34 ms 680 KB Output is correct
3 Correct 34 ms 688 KB Output is correct
4 Correct 34 ms 588 KB Output is correct
5 Correct 34 ms 692 KB Output is correct
6 Correct 34 ms 588 KB Output is correct
7 Correct 35 ms 640 KB Output is correct
8 Correct 35 ms 588 KB Output is correct
9 Correct 34 ms 588 KB Output is correct
10 Correct 34 ms 600 KB Output is correct
11 Correct 41 ms 588 KB Output is correct
12 Correct 35 ms 588 KB Output is correct
13 Correct 31 ms 588 KB Output is correct
14 Correct 34 ms 588 KB Output is correct
15 Correct 34 ms 568 KB Output is correct
16 Correct 33 ms 588 KB Output is correct
17 Correct 30 ms 588 KB Output is correct
18 Correct 29 ms 664 KB Output is correct
19 Correct 31 ms 588 KB Output is correct
20 Correct 28 ms 588 KB Output is correct
21 Correct 31 ms 644 KB Output is correct
22 Correct 29 ms 588 KB Output is correct
23 Correct 27 ms 644 KB Output is correct
24 Correct 30 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 588 KB Output is correct
2 Correct 35 ms 588 KB Output is correct
3 Correct 34 ms 576 KB Output is correct
4 Correct 34 ms 588 KB Output is correct
5 Correct 35 ms 676 KB Output is correct
6 Correct 36 ms 588 KB Output is correct
7 Correct 38 ms 580 KB Output is correct
8 Correct 34 ms 588 KB Output is correct
9 Correct 34 ms 588 KB Output is correct
10 Correct 35 ms 588 KB Output is correct
11 Correct 34 ms 588 KB Output is correct
12 Correct 34 ms 588 KB Output is correct
13 Correct 34 ms 588 KB Output is correct
14 Execution timed out 3053 ms 23100 KB Time limit exceeded
15 Halted 0 ms 0 KB -