QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465913#8468. Collinear ArrangementslamWA 1ms6880kbC++143.7kb2024-07-07 13:38:032024-07-07 13:38:03

Judging History

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

  • [2024-07-07 13:38:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6880kb
  • [2024-07-07 13:38:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 200005
struct Vec
{
	int x,y;
	Vec(int a=0,int b=0) {x=a,y=b;}
};
Vec operator + (const Vec &x,const Vec &y) {return Vec(x.x+y.x,x.y+y.y);}
Vec operator - (const Vec &x,const Vec &y) {return Vec(x.x-y.x,x.y-y.y);}
Vec operator * (const Vec &x,const int y) {return Vec(x.x*y,x.y*y);}
Vec operator / (const Vec &x,const int y) {return Vec(x.x/y,x.y/y);}
int cdot(const Vec &x,const Vec &y) {return x.x*y.x+x.y*y.y;}
int cross(const Vec &x,const Vec &y) {return x.x*y.y-x.y*y.x;}
int norm(Vec x) {return x.x*x.x+x.y*x.y;}
Vec rot90(Vec x) {return Vec(x.y,-x.x);}
Vec a[N];
int n,QQ;
signed main()
{
	cin>>n>>QQ;
	for(int i=1;i<=n;i++) a[i].x=read(),a[i].y=read(),a[i+n]=a[i];
	a[n+n+1]=a[1];
	while(QQ--)
	{
		int op=read();
		if(op==2)
		{
			Vec P,Q;
			P.x=read(),P.y=read();
			Q.x=read(),Q.y=read();
			Vec v=rot90(Q-P);
			int orig=1;
			while(cdot(a[orig+1]-a[orig],v)==0) orig++;
			int c1=orig;
			if(cdot(a[c1+1]-a[c1],v)<0) v=v*(-1);
			// printf("%d %d\n",v.x,v.y);
			for(int i=17;i>=0;i--)
			{
				if(c1+(1<<i)<=orig+n-1)
				{
					int tw=c1+(1<<i);
					if(cdot(v,a[tw+1]-a[tw])>0&&cdot(v,a[tw]-a[c1])>=0) c1+=(1<<i);
				}
			}
			c1=c1%n+1;
			int c2=c1;
			v=v*(-1);
			// printf("%d %d\n",v.x,v.y);
			// cout<<cdot(v,a[tw]-a[i])<<endl;
			for(int i=17;i>=0;i--)
			{
				if(c2+(1<<i)<=c1+n-1)
				{
					int tw=c2+(1<<i);
					if(cdot(v,a[tw+1]-a[tw])>0&&cdot(v,a[tw]-a[c2])>=0) c2+=(1<<i);
				}
			}
			c2++;
			// printf("%d %d\n",c1,c2);
			auto find=[&](int l,int r)->int
			{
				int o=cross(Q-P,a[l]-P);
				if(o==0) return 1;
				while(l<=r)
				{
					int mid=(l+r)/2;
					int tw=cross(Q-P,a[mid]-P);
					if(tw==0) return 1;
					if((tw>0)==(o>0)) l=mid+1;
					else r=mid-1;
				}
				return 0;
			};
			int ans=0;
			ans+=find(orig+1,c1);
			ans+=find(c1+1,orig+n);
			printf("%lld\n",ans);
		}
		else
		{
			Vec P;
			P.x=read(),P.y=read();
			int siz1=0,siz2=0;
			for(int i=1;i<=n;i++) siz1+=abs(cross(a[i+1]-P,a[i]-P));
			for(int i=2;i+1<=n;i++) siz2+=abs(cross(a[i+1]-a[1],a[i]-a[1]));
			// printf("%d %d\n",siz1,siz2);
			if(siz1==siz2)
			{
				int ans=0,j=1;
				for(int i=1;i<=n;i++)
				{
					while(i==j||cross(a[i]-P,a[j]-P)>0) j++;
					// printf("%d %d %d\n",i,j,cross(a[i]-P,a[j]-P));
					if(cross(a[i]-P,a[j]-P)==0) ans++;
				}
				printf("%d\n",ans/2);
			}
			else
			{
				int l=1,r=1;
				for(int i=2;i<=n;i++)
				{
					if(cross(P-a[l],P-a[i])>0 || (cross(P-a[l],P-a[i])==0&&norm(P-a[i])>norm(P-a[l]))) l=i;
					if(cross(P-a[r],P-a[i])<0 || (cross(P-a[r],P-a[i])==0&&norm(P-a[i])>norm(P-a[r]))) r=i;
				}
				swap(l,r);
				// printf("%d %d\n",l,r);
				int cl=l,cr=l-1+n,ans=0;
				if((r+1)%n==l%n) {}
				else
				{
					while(1)
					{
						if(cross(P-a[cl],P-a[cr])==0) ans++;
						// printf("* %d %d\n",cl,cr);
						if(cl%n==r%n&&cr%n==(r+1)%n) break;
						if(cl%n==r%n) cr--;
						else if(cr%n==(r+1)%n) cl++;
						else
						{
							if(cross(P-a[cl],P-a[cr])>0) cl++;
							else cr--;
						}
					}
				}
				printf("%d\n",ans);
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6880kb

input:

5 3
0 0
2 0
2 1
1 2
0 2
1 1 1
2 1 1 2 2
1 2 2

output:

1
0
2

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'