QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462059 | #8468. Collinear Arrangements | ucup-team052# | WA | 3ms | 7072kb | C++23 | 3.6kb | 2024-07-03 13:29:50 | 2024-07-03 13:29:52 |
Judging History
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 c1=n+1;
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)<=n+n)
{
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(c1,c2-1);
ans+=find(c2,c1+n-1);
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: 100
Accepted
time: 0ms
memory: 7072kb
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 1 2
result:
ok 3 number(s): "1 1 2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6884kb
input:
3 1 0 0 1 0 0 1 2 1 1 2 2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 6884kb
input:
1000 1 -139438978 -172098481 -125097652 -169056403 155419484 -28898293 186215972 6874955 240691742 77644763 334255616 236444333 342049790 274206233 342049766 274611851 342049472 275025569 342049298 275242193 342048794 275724449 341967248 297262013 341966000 297569423 341963012 298092233 341960624 29...
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 6876kb
input:
1000 1000 -468718512 100559444 -466285968 100587272 -463035240 100649294 -461326068 100761398 -459427038 100900610 -455064924 101233256 -452216364 101462348 -450021522 101653544 -449086266 101738960 -433665372 103152428 -429959922 103532498 -427457166 103795826 -418983006 104802926 -416443854 105124...
output:
1 2 2 1 1 2 1 2 1 2 1 1 1 0 0 1 2 1 1 2 0 0 0 2 0 2 2 1 1 1 1 1 1 0 0 1 1 2 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 2 1 2 1 0 0 1 1 2 1 1 0 1 1 2 0 1 0 0 2 1 0 1 0 0 0 1 2 1 2 0 1 0 0 1 1 0 0 0 2 2 1 0 2 1 0 1 1 1 1 1 0 1 1 1 1 2 1 1 2 1 2 2 0 2 2 0 0 0 2 1 0 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0 1 1 1 1 0 0 0 2 1 ...
result:
wrong answer 281st numbers differ - expected: '2', found: '1'