QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#373104 | #4371. Spin Doctor | InfinityNS | TL | 325ms | 21088kb | C++14 | 5.0kb | 2024-04-01 02:28:39 | 2024-04-01 02:28:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
struct pt{
ll x,y;
pt():x(0),y(0){}
pt(ll a,ll b):x(a),y(b){}
};
pt operator - (pt a,pt b){return pt(a.x-b.x,a.y-b.y);}
pt operator - (pt a){return pt(-a.x,-a.y);}
ll cross(pt a,pt b){return a.x*b.y-a.y*b.x;}
ll dot(pt a,pt b){return a.x*b.x+a.y*b.y;}
int part(pt a){return a.y<0 || (a.y==0 && a.x<0);}
bool operator < (pt a,pt b){return mp(part(a),(ll)0)<mp(part(b),cross(a,b));}
bool operator == (pt a,pt b){return mp(a.x,a.y)==mp(b.x,b.y);}
int sgn(ll x){return x==0?0:(x<0?-1:1);}
const int N=250050;
pt pts[N];
int c[N],n;
bool cmp(pt a,pt b){return mp(a.x,a.y)<mp(b.x,b.y);}
vector<pt> ConvexHull(vector<pt> poly){
sort(poly.begin(),poly.end(),cmp);
poly.erase(unique(poly.begin(),poly.end()),poly.end());
if(poly.size()<2)return poly;
vector<pt> hull;
int sz=0;
for(int t=0;t<2;t++){
int was=sz;
for(auto p:poly){
while(sz>was+1 && cross(hull[sz-1]-hull[sz-2],p-hull[sz-2])<=0){
hull.pop_back();
sz--;
}
hull.pb(p);
sz++;
}
hull.pop_back();
sz--;
reverse(poly.begin(),poly.end());
}
return hull;
}
bool OnSeg(pt a,pt b,pt p){
pt v=b-a;
if(cross(v,p-a)!=0)return false;
ll da=dot(v,a);
ll dp=dot(v,p);
ll db=dot(v,b);
return da<=dp && dp<=db;
}
bool InTriangle(pt a,pt b,pt c,pt p){
vector<pt> poly={a,b,c};
bool lo=false,hi=false;
for(int i=0;i<3;i++){
ll cr=cross(poly[i]-p,poly[(i+1)%3]-p);
if(cr<0)lo=true;
if(cr>0)hi=true;
}
return !lo || !hi;
}
bool Inside(vector<pt>& poly, pt p){
if(poly.size()==1)return p==poly[0];
if(poly.size()==2)return OnSeg(poly[0],poly[1],p);
int bot=0,top=(int)poly.size()-3,ans=0;
while(bot<=top){
int mid=top+bot>>1;
if(cross(poly[mid]-poly.back(),p-poly.back())>=0){
bot=mid+1;
ans=mid;
}else{
top=mid-1;
}
}
//printf("Inside? %i\n",ans);
return InTriangle(poly[ans],poly[ans+1],poly.back(),p);
}
pt Solve(vector<pt>& poly,pt p,int l,int r,int sg){
/*int bot=l,top=r-1,ans=r;
while(bot<=top){
int mid=bot+top>>1;
if(sgn(cross(poly[mid]-p,poly[mid+1]-p))==sg){
bot=mid+1;
}else{
ans=mid;
top=mid-1;
}
}
//printf("Solve (%lld, %lld) l:%i r:%i -- %i (%lld, %lld)\n",p.x,p.y,l,r,ans,poly[ans].x,poly[ans].y);
return poly[ans]-p;*/
int ans=l;
while(ans<r && sgn(cross(poly[ans]-p,poly[ans+1]-p))==sg)ans++;
return poly[ans]-p;
}
pair<pt,pt> Tangents(vector<pt>& poly, pt p){
/*int l=0,r=0;
for(int i=0;i<poly.size();i++){
if(sgn(cross(poly[l]-p,poly[i]-p))==1){
l=i;
}
if(sgn(cross(poly[r]-p,poly[i]-p))==-1){
r=i;
}
}
return {poly[l]-p,poly[r]-p};*/
if(poly.size()==1)return {poly[0]-p,poly[0]-p};
if(poly.size()==2){
if(cross(poly[0]-p,poly[1]-p)<=0)return {poly[0]-p,poly[1]-p};
else return {poly[1]-p,poly[0]-p};
}
int bot=1,top=(int)poly.size()-2,ans=0;
int s1=sgn(cross(poly.back()-p,poly.front()-p));
while(top>=bot){
int mid=top+bot>>1;
if(sgn(cross(poly.back()-p,poly[mid]-p))==s1){
ans=mid;
bot=mid+1;
}else{
top=mid-1;
}
}
//printf("Split\n");
//for(int i=0;i<=ans;i++)printf("(%lld, %lld) ",poly[i].x,poly[i].y);printf("\n");
//for(int i=ans+1;i<poly.size();i++)printf("(%lld, %lld) ",poly[i].x,poly[i].y);printf("\n");
//if(n==100 && s1==0)printf("s1 before %i\n",s1);
if(s1==0)s1=-sgn(cross(poly.back()-p,poly[ans+1]-p));
pt L=Solve(poly,p,0,ans,s1);
pt R=Solve(poly,p,ans+1,(int)poly.size()-1,-s1);
if(s1==-1)swap(L,R);
return {L,R};
}
int main(){
scanf("%i",&n);
vector<pt> poly;
for(int i=1;i<=n;i++){
scanf("%lld %lld %i",&pts[i].x,&pts[i].y,&c[i]);
if(c[i]==1)poly.pb(pts[i]);
}
if(poly.size()==1){
printf("1\n");
return 0;
}
poly=ConvexHull(poly);
//if(n==100)printf("CH size: %i\n",poly.size());
//printf("Convex hull: ");
//for(pt p:poly)printf("(%lld, %lld) ",p.x,p.y);
//printf("\n");
ll mny=poly[0].y,mxy=poly[0].y;
for(int i=1;i<poly.size();i++){
mny=min(mny,poly[i].y);
mxy=max(mxy,poly[i].y);
}
int cnt=0;
vector<pt> cand;
for(int i=1;i<=n;i++){
if(Inside(poly,pts[i])){
//printf("%i(%lld, %lld) is inside\n",i,pts[i].x,pts[i].y);
cnt++;
}else{
cand.pb(pts[i]);
}
}
//if(n==100)printf("Inside %i\n",cnt);
vector<pair<pt,int>> evs;
for(int i=0;i<cand.size();i++){
//printf("Cand (%lld, %lld)\n",cand[i].x,cand[i].y);
pt L,R;
tie(L,R)=Tangents(poly,cand[i]);
//printf("Tangents L(%lld, %lld) R(%lld, %lld)\n",L.x,L.y,R.x,R.y);
if(part(L)==1)L=-L;
if(part(R)==1)R=-R;
pt S=R;
pt E=L;
evs.pb({S,-1});
evs.pb({E,1});
//printf("(%lld, %lld) enter(%lld, %lld) exit(%lld, %lld)\n",cand[i].x,cand[i].y,S.x,S.y,E.x,E.y);
//if(L<R)cnt++;
if(E<S)cnt++;
//if(cand[i].y>=mny && cand[i].y<=mxy)cnt++;
}
int ans=cnt;
sort(evs.begin(),evs.end());
for(auto ev:evs){
cnt-=ev.second;
ans=min(ans,cnt);
}
printf("%i\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7660kb
input:
6 0 10 0 10 0 1 12 8 1 5 5 0 11 2 1 11 3 0
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 7684kb
input:
10 6 1 1 0 2 0 2 1 1 6 1 1 8 2 0 4 4 0 4 0 0 2 3 1 6 1 0 6 3 1
output:
8
result:
ok single line: '8'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7792kb
input:
5 5 7 0 3 4 0 5 7 0 5 7 1 9 4 0
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 7716kb
input:
100 7487 4751 1 7499 5064 1 7471 5376 1 7404 5683 1 7300 5979 1 7159 6260 1 6984 6520 1 6777 6757 1 6543 6966 1 6284 7144 1 6006 7288 1 5711 7396 1 5405 7466 1 5092 7498 1 4780 7490 1 4469 7442 1 4167 7357 1 3878 7234 1 3607 7075 1 3358 6884 1 3135 6664 1 2941 6417 1 2780 6147 1 2653 5860 1 2564 555...
output:
61
result:
ok single line: '61'
Test #5:
score: 0
Accepted
time: 2ms
memory: 7716kb
input:
200 7489 1285 0 6851 8471 0 6122 2766 1 2413 9338 0 1725 7382 0 6984 6520 1 5080 8417 0 2604 5711 1 5833 2643 1 48 2810 0 5316 2439 0 900 7419 0 6809 867 0 6006 7288 1 5092 7498 1 5531 2558 1 7075 6393 1 9979 9313 0 7436 4441 1 4595 2534 1 2598 909 0 842 284 0 3358 6884 1 6522 7976 0 604 5833 0 3607...
output:
125
result:
ok single line: '125'
Test #6:
score: 0
Accepted
time: 0ms
memory: 8548kb
input:
300 2253 823 1 1865 9556 0 306 6720 1 8588 1519 1 2756 9468 1 5810 9933 1 1625 9138 0 27 932 0 8124 1097 1 8699 8363 1 7202 9489 1 9420 7337 1 9862 6164 1 908 2128 1 9341 2521 1 372 8140 0 9318 7520 1 1760 34 0 785 612 0 1445 1442 0 9694 3280 1 9496 2152 0 9249 1891 0 2162 9828 0 580 2663 1 1269 832...
output:
234
result:
ok single line: '234'
Test #7:
score: 0
Accepted
time: 63ms
memory: 13316kb
input:
100000 7487 4751 1 7487 4751 1 7487 4752 1 7487 4752 1 7487 4752 1 7487 4752 1 7487 4753 1 7487 4753 1 7487 4753 1 7487 4754 1 7487 4754 1 7487 4754 1 7487 4755 1 7487 4755 1 7487 4755 1 7487 4756 1 7488 4756 1 7488 4756 1 7488 4757 1 7488 4757 1 7488 4757 1 7488 4757 1 7488 4758 1 7488 4758 1 7488 ...
output:
68833
result:
ok single line: '68833'
Test #8:
score: 0
Accepted
time: 69ms
memory: 13312kb
input:
100000 8980 4601 1 8980 4602 1 8980 4602 1 8980 4603 1 8980 4603 1 8980 4604 1 8980 4604 1 8980 4605 1 8980 4605 1 8980 4606 1 8980 4606 1 8980 4607 1 8980 4607 1 8980 4608 1 8980 4608 1 8980 4609 1 8980 4609 1 8980 4610 1 8980 4610 1 8980 4611 1 8981 4611 1 8981 4612 1 8981 4612 1 8981 4613 1 8981 ...
output:
79761
result:
ok single line: '79761'
Test #9:
score: 0
Accepted
time: 74ms
memory: 13308kb
input:
100000 9975 4501 1 9975 4502 1 9975 4503 1 9975 4503 1 9975 4504 1 9975 4504 1 9975 4505 1 9975 4506 1 9975 4506 1 9975 4507 1 9975 4508 1 9975 4508 1 9975 4509 1 9975 4509 1 9975 4510 1 9975 4511 1 9976 4511 1 9976 4512 1 9976 4513 1 9976 4513 1 9976 4514 1 9976 4514 1 9976 4515 1 9976 4516 1 9976 ...
output:
79877
result:
ok single line: '79877'
Test #10:
score: 0
Accepted
time: 212ms
memory: 13360kb
input:
100000 89749 223387 0 295171 424382 0 397151 279092 1 393939 207794 1 109069 198636 1 338201 128673 1 388987 306412 1 401174 201459 0 428943 426416 0 292775 106229 1 181076 383227 1 207577 106125 1 389057 405639 0 358258 146173 1 376103 425370 0 284279 396030 1 342155 368352 1 479748 52614 0 102762 ...
output:
72070
result:
ok single line: '72070'
Test #11:
score: 0
Accepted
time: 108ms
memory: 13804kb
input:
100000 649 24758 0 14496 41252 0 39286 10853 0 19975 37285 1 40085 29490 0 1766 27831 0 5842 586 0 27105 8225 1 11312 32491 1 17523 4856 0 16990 8550 1 4916 12992 0 7696 24913 1 42700 5177 0 43755 27268 0 9922 42370 0 8555 16976 1 17794 36896 0 21532 37468 1 35271 30549 0 31468 10477 1 37030 18776 1...
output:
74280
result:
ok single line: '74280'
Test #12:
score: 0
Accepted
time: 2ms
memory: 8424kb
input:
3 100 100 1 500 500 1 200 200 0
output:
3
result:
ok single line: '3'
Test #13:
score: 0
Accepted
time: 2ms
memory: 7944kb
input:
5 0 100 0 0 200 1 0 300 0 0 400 1 0 500 0
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 0ms
memory: 8348kb
input:
7 100 0 0 200 0 1 300 0 0 400 0 1 500 0 0 600 0 1 700 0 0
output:
5
result:
ok single line: '5'
Test #15:
score: 0
Accepted
time: 1ms
memory: 8160kb
input:
5 0 0 1 100 100 1 50 50 0 50 25 0 25 50 0
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 1ms
memory: 7988kb
input:
1 0 0 1
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 8248kb
input:
2 0 0 1 0 0 0
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 2ms
memory: 7664kb
input:
2 0 0 1 0 1 0
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 2ms
memory: 8008kb
input:
5 100 100 1 50 50 0 100 200 0 150 150 0 100 100 0
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 37ms
memory: 9300kb
input:
250000 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964018 389997 0 1964...
output:
250000
result:
ok single line: '250000'
Test #21:
score: 0
Accepted
time: 213ms
memory: 21088kb
input:
250000 8550 5546 1 1572 3657 1 7112 3904 1 4958 6472 1 6621 8971 1 7230 7901 1 1460 4459 1 3076 5535 1 2823 3202 1 4314 6444 1 5323 9275 1 976 6014 1 9105 7435 1 6937 5228 1 6610 5712 1 8099 5810 1 7207 2629 1 9527 3777 1 3790 3671 1 3223 9511 1 922 2799 1 2708 4697 1 5454 9118 1 7530 9036 1 885 429...
output:
203548
result:
ok single line: '203548'
Test #22:
score: 0
Accepted
time: 150ms
memory: 17344kb
input:
100000 6586 9605 1 688 2874 1 8700 7949 1 4623 47 1 378 3451 1 5368 46 1 309 6390 1 9344 2926 1 8645 8012 1 9105 7435 1 6101 204 1 26 5094 1 41 5318 1 3223 9511 1 9691 6390 1 7664 8934 1 7007 9384 1 1637 8315 1 7530 9036 1 119 4206 1 8082 1418 1 4053 158 1 7263 9224 1 6658 429 1 1883 8550 1 5094 997...
output:
63494
result:
ok single line: '63494'
Test #23:
score: 0
Accepted
time: 325ms
memory: 18164kb
input:
100000 42796 30581 1 27459 44131 1 42756 14344 1 44098 17439 1 18059 44290 1 3096 32112 1 29881 1849 1 42046 13114 1 1641 29437 1 12475 41636 1 10539 4777 1 1458 29023 1 25506 359 1 41181 11813 1 17727 810 1 24795 44765 1 31345 2629 1 14436 2195 1 33256 41132 1 2325 30806 1 4517 34129 1 42771 30628 ...
output:
64584
result:
ok single line: '64584'
Test #24:
score: -100
Time Limit Exceeded
input:
250000 179223 507524 1 1953878 749817 1 1074428 1995760 1 1038476 1261 1 1873442 1414315 1 1997919 1050970 1 1994767 916993 1 1441559 143861 1 1873064 1414930 1 1021459 1999488 1 1999780 991906 1 46502 748785 1 134097 573595 1 1761948 1566969 1 564999 1860407 1 258192 1590279 1 1305866 68863 1 10008...