QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201791#5155. Faster Than Lightnameless_story#WA 124ms22232kbC++204.1kb2023-10-05 16:46:592023-10-05 16:47:00

Judging History

你现在查看的是最新测评结果

  • [2023-10-05 16:47:00]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:22232kb
  • [2023-10-05 16:46:59]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
struct Q
{
	ll x,y;
	Q operator+(const Q &o) const { return {x+o.x,y+o.y}; }
	Q operator-(const Q &o) const { return {x-o.x,y-o.y}; }
	ll operator*(const Q &o) const { return x*o.y-y*o.x; }
	ll operator&(const Q &o) const { return x*o.x+y*o.y; }
	bool operator!=(const Q &o) const { return x!=o.x||y!=o.y; }
	Q &operator+=(const Q &o) { x+=o.x; y+=o.y; return *this; }
	ll len2() const { return x*x+y*y; }
};
bool operator<(const Q &a,const Q &b)
{
	ll s=a*b;
	return s>0||s==0&&a.len2()<b.len2();
}
struct convex
{
	vector<Q> p;
	convex(vector<Q> a)
	{
		int n=a.size(),i;
		if (!n) return;
		p=a;
		for (i=1; i<n; i++) if (p[i].x<p[0].x||p[i].x==p[0].x&&p[i].y<p[0].y) swap(p[0],p[i]);
		a.resize(0); a.reserve(n);
		for (i=1; i<n; i++) if (p[i]!=p[0]) a.push_back(p[i]-p[0]);
		sort(all(a));
		for (i=0; i<a.size(); i++) a[i]+=p[0];
		Q *st=p.data()-1;
		int tp=1;
		for (auto &v:a)
		{
			while (tp>1&&(st[tp]-st[tp-1])*(v-st[tp-1])<=0) --tp;
			st[++tp]=v;
		}
		p.resize(tp);
	}
};
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cout<<fixed<<setprecision(15);
	int n,i;
	cin>>n;
	vector<array<ll,4>> axis(n);
	for (auto &[x1,y1,x2,y2]:axis) cin>>x1>>y1>>x2>>y2;
	auto sol2=[&](vector<Q> a,vector<Q> b)
		{
			auto e=b;
			// for (auto [x,y]:a) cerr<<"("<<x<<", "<<y<<")\n"; cerr<<endl;
			// for (auto [x,y]:b) cerr<<"("<<x<<", "<<y<<")\n"; cerr<<endl;
			n=a.size();
			a.push_back(a[0]);
			int m=b.size();
			sort(all(b),[&](Q a,Q b) { return a.x==b.x?a.y<b.y:a.x<b.x; });
			{
				vector<Q> c={b[0]};
				b.erase(b.begin());
				int tp=0;
				for (Q o:b)
				{
					if (c[tp].y<=o.y) continue;
					while (tp>=1&&(o-c[tp-1])*(c[tp]-c[tp-1])>=0)
					{
						--tp;
						c.pop_back();
					}
					c.push_back(o);
					++tp;
				}
				swap(b,c);
			}
			for (auto &[x,y]:b) x=-x,y=-y;
			{
				vector<Q> c={b[0]};
				b.erase(b.begin());
				int tp=0;
				for (Q o:b)
				{
					if (c[tp].y<=o.y) continue;
					while (tp>=1&&(o-c[tp-1])*(c[tp]-c[tp-1])>=0)
					{
						--tp;
						c.pop_back();
					}
					c.push_back(o);
					++tp;
				}
				swap(b,c);
			}
			for (auto &[x,y]:b) x=-x,y=-y;
			swap(b,e);
			m=b.size();
			// for (auto [x,y]:b) cerr<<"("<<x<<", "<<y<<")\n"; cerr<<endl;
			// for (auto [x,y]:e) cerr<<"("<<x<<", "<<y<<")\n"; cerr<<endl;
			for (i=0; i<n; i++)
			{
				// cerr<<i<<' '<<a[i].x<<' '<<a[i].y<<' '<<a[i+1].x<<' '<<a[i+1].y<<endl;
				auto d=a[i+1]-a[i];
				swap(d.x,d.y); d.y=-d.y;
				ll C=d&a[i];
				auto o=a[(i+n-1)%n];
				ll sgn=(d&o)-C;
				// cerr<<sgn<<endl;
				assert(sgn);
				if (sgn<0) sgn=-1; else sgn=1;
				int l=0,r=m-1,mid;
				while (l<r)
				{
					mid=l+r>>1;
					if (((b[mid]&d)-(b[mid+1]&d))*sgn<0) l=mid+1;
					else r=mid;
				}
				ll D=(b[l]&d)-C;
				// cerr<<D<<endl;rf
				if (D)
				{
					if (D<0) D=-1; else D=1;
				}
				if (D==sgn) continue;
				int q=e.size();
				l=0,r=q-1,mid;
				while (l<r)
				{
					mid=l+r>>1;
					if (((e[mid]&d)-(e[mid+1]&d))*sgn<0) l=mid+1;
					else r=mid;
				}
				D=(e[l]&d)-C;
				// cerr<<D<<' '<<sgn<<' '<<d.x<<' '<<d.y<<endl;
				if (D)
				{
					if (D<0) D=-1; else D=1;
				}
				if (D!=sgn) return 1;
			}
			return 0;
		};
	auto solve=[&](const vector<array<ll,4>> &axis) -> bool
		{
			int n=axis.size(),i,j;
			vector<Q> a(n),b(n);
			for (i=0; i<n; i++) a[i]={axis[i][0],axis[i][1]};
			for (i=0; i<n; i++) b[i]={axis[i][2],axis[i][3]};
			a=convex(a).p;
			b=convex(b).p;
			if (a.size()<=2||b.size()<=2) return 1;
			if (sol2(a,b)) return 1;
			for (auto &[x,y]:a) x=-x,y=-y;
			for (auto &[x,y]:b) x=-x,y=-y;
			return sol2(b,a);
		};
	if (solve(axis))
	{
		cout<<"possible\n";
		return 0;
	}
	else
	{
		for (auto &[x1,y1,x2,y2]:axis) swap(x1,x2),x1=-x1,x2=-x2;
		if (solve(axis)) cout<<"possible\n";
		else cout<<"impossible\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

5
1 3 3 4
2 2 4 3
4 1 5 3
5 2 7 3
6 3 8 4

output:

possible

result:

ok single line: 'possible'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

4
1 1 2 2
1 3 2 4
3 1 4 2
3 3 4 4

output:

impossible

result:

ok single line: 'impossible'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

3
1 1 2 2
1 3 2 4
3 3 4 4

output:

possible

result:

ok single line: 'possible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

5
0 0 1 999999999
0 999999999 999999999 1000000000
1 0 999999998 1
999999998 0 999999999 999999999
2 999999998 3 999999999

output:

impossible

result:

ok single line: 'impossible'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

4
0 1 1 1000000000
1 0 999999999 1
999999999 0 1000000000 999999999
2 999999999 999999999 1000000000

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

3
0 0 1 1000000000
2 0 999999999 1
2 999999999 999999999 1000000000

output:

impossible

result:

ok single line: 'impossible'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

3
0 0 1 1000000000
2 0 999999999 1
2 999999999 1000000000 1000000000

output:

possible

result:

ok single line: 'possible'

Test #8:

score: 0
Accepted
time: 123ms
memory: 22232kb

input:

199999
433914929 216935871 433914930 216935872
621822279 310889546 621822280 310889547
395914333 197935573 395914334 197935574
582775641 291366227 582775642 291366228
658726133 329341473 658726134 329341474
71689261 35823037 71689262 35823038
453260967 226608890 453260968 226608891
249802825 1248798...

output:

impossible

result:

ok single line: 'impossible'

Test #9:

score: 0
Accepted
time: 124ms
memory: 22080kb

input:

199999
783545903 638444708 783545904 638444709
129510863 105527268 129510864 105527269
844145756 687822366 844145757 687822367
69111161 56312696 69111162 56312697
820438487 668505332 820438488 668505333
541037357 440845152 541037358 440845153
201057677 163824672 201057678 163824673
132372296 1078588...

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: 0
Accepted
time: 122ms
memory: 21936kb

input:

199999
90035476 60020102 90035477 60020103
482291029 321523804 482291030 321523805
943496815 628994328 943496816 628994329
278866936 185907742 278866937 185907743
310938589 207288844 310938590 207288845
203677765 135781628 203677766 135781629
368744134 245825874 368744135 245825875
559390024 3729231...

output:

impossible

result:

ok single line: 'impossible'

Test #11:

score: 0
Accepted
time: 114ms
memory: 21980kb

input:

199999
207687261 415417709 207687262 415417710
150460947 300965081 150460948 300965082
9349830 18742847 9349831 18742848
87879837 175802861 87879838 175802862
354035800 708114787 354035801 708114788
305159254 610361695 305159255 610361696
248609913 497263013 248609914 497263014
499646110 999335407 4...

output:

impossible

result:

ok single line: 'impossible'

Test #12:

score: 0
Accepted
time: 123ms
memory: 22164kb

input:

199999
79738802 97861382 79738803 97861383
614827422 754561052 614827423 754561053
517213290 634761890 517213291 634761891
788424494 967612004 788424495 967612005
613541698 752983118 613541699 752983119
698980304 857839589 698980305 857839590
487475098 598265018 487475099 598265019
733711836 9004646...

output:

impossible

result:

ok single line: 'impossible'

Test #13:

score: 0
Accepted
time: 121ms
memory: 21956kb

input:

199999
161399962 242105266 161399963 242105267
385751852 578633101 385751853 578633102
222705450 334063498 222705451 334063499
503730932 755601721 503730933 755601722
454037530 681061618 454037531 681061619
334605270 501913228 334605271 501913229
478675624 718018759 478675625 718018760
137316204 205...

output:

impossible

result:

ok single line: 'impossible'

Test #14:

score: -100
Wrong Answer
time: 86ms
memory: 22040kb

input:

199999
222639792 110935680 222639793 110935683
931931336 465581452 931931337 465581455
35474718 17353143 35474719 17353146
206777070 103004319 206777071 103004322
914064786 456648177 914064787 456648180
301496196 150363882 301496197 150363885
515345552 257288560 515345553 257288563
500949336 2500904...

output:

possible

result:

wrong answer 1st lines differ - expected: 'impossible', found: 'possible'