QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657951#7015. Rikka with IlluminationsexpectantAC ✓550ms40120kbC++142.5kb2024-10-19 15:50:462024-10-19 15:50:46

Judging History

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

  • [2024-10-19 15:50:46]
  • 评测
  • 测评结果:AC
  • 用时:550ms
  • 内存:40120kb
  • [2024-10-19 15:50:46]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define drp(i,j,k) for(int i=j;i>=(k);--i)
#define MAXN 1000005
typedef long long ll;
int task,n,m,l[MAXN],r[MAXN];
std::vector<int> vec[MAXN];
struct data{
    int l,r,id;
    inline bool operator < (const data &rhs)const{
        return l<rhs.l;
    }
}seq[MAXN],tmp[MAXN];
struct point{
    ll x,y;
    inline point operator + (const point &rhs)const{
        return (point){x+rhs.x,y+rhs.y};
    }
    inline point operator - (const point &rhs)const{
        return (point){x-rhs.x,y-rhs.y};
    }
}a[MAXN],b[MAXN];
inline ll cross(const point &lhs,const point &rhs){
    return lhs.x*rhs.y-lhs.y*rhs.x;
}
inline std::vector<int> solve(int x){
    int cnt=0,id=0,pos=1,st=seq[x].l,cur=seq[x].r;
    std::vector<int> ret;
    ret.push_back(seq[x].id);
    rep(i,x,m) tmp[++cnt]=seq[i];
    rep(i,1,x-1) tmp[++cnt]=seq[i],tmp[cnt].l+=n,tmp[cnt].r+=n;
    rep(i,st,st+n-1){
        while(pos<cnt&&tmp[pos+1].l==i){
            ++pos;
            if(tmp[pos].r>tmp[id].r) id=pos;
        }
        if(i==cur){
            if(tmp[id].r<=i) return std::vector<int>();
            cur=tmp[id].r,ret.push_back(tmp[id].id),id=0;
        }
    }
    return ret;
}
inline void print(){
    int pos=0;
    rep(i,1,m) if(!vec[i].empty()&&(!pos||vec[i].size()<vec[pos].size())) pos=i;
    if(!pos) std::cout<<-1<<'\n';
    else{
        std::cout<<vec[pos].size()<<'\n';
        rep(i,0,(int)vec[pos].size()-1) std::cout<<vec[pos][i]<<" \n"[i==(int)vec[pos].size()-1];
    }
}
inline void init(){
    rep(i,1,m) std::vector<int>().swap(vec[i]);
}
int main(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0),std::cout.tie(0);
    std::cin>>task;
    while(task--){
        std::cin>>n>>m,init();
        rep(i,1,n) std::cin>>a[i].x>>a[i].y;
        std::reverse(a+1,a+n+1);
        rep(i,1,m) std::cin>>b[i].x>>b[i].y;
        rep(i,1,m){
            int cntl=0,cntr=0;
            rep(cur,1,n){
                int lst=cur==1?n:cur-1,nxt=cur==n?1:cur+1;
                if(cross(a[cur]-b[i],a[cur]-a[lst])<0&&cross(a[cur]-b[i],a[nxt]-a[cur])>0) ++cntl,l[i]=cur;
                if(cross(a[cur]-b[i],a[cur]-a[lst])>0&&cross(a[cur]-b[i],a[nxt]-a[cur])<0) ++cntr,r[i]=cur;
            }
            assert(cntl==1&&cntr==1);
            if(l[i]>r[i]) r[i]+=n;
            seq[i]=(data){l[i],r[i],i};
        }
        std::sort(seq+1,seq+m+1);
        rep(i,1,m) vec[i]=solve(i);
        print();
    }
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
3 3
0 0
1 0
0 1
-1 -1
3 -1
-1 3

output:

2
2 3

result:

ok 1 cases.

Test #2:

score: 0
Accepted
time: 51ms
memory: 39168kb

input:

100
13 17
-976 -766
-628 -956
462 -987
967 -997
981 -123
919 115
847 336
692 789
350 908
-558 996
-843 944
-944 400
-974 -476
-41876798 919231678
-375313647 26070145
-288061228 527643156
-93144407 730297
93699145 -260606010
-393321698 -339399089
644245933 784344503
-731740672 525632046
-32141854 114...

output:

2
12 4
-1
-1
-1
-1
3
20 17 12
-1
4
3 27 13 16
-1
-1
-1
8
10 2 14 3 7 15 8 11
4
8 6 7 5
-1
3
2 3 7
-1
-1
-1
-1
-1
4
5 2 8 13
4
12 3 13 7
4
1 7 5 4
4
25 48 17 13
4
3 38 22 23
5
6 22 40 37 34
37
65 75 85 13 52 53 36 81 37 91 30 69 3 56 46 89 12 9 61 15 10 19 51 38 76 26 83 71 74 33 57 22 70 8 58 90 54
...

result:

ok 100 cases.

Test #3:

score: 0
Accepted
time: 498ms
memory: 38644kb

input:

100
1000 1000
-206566811 272513
-206555115 -2214957
-206550642 -2598812
-206538524 -3429227
-206534118 -3685047
-206497885 -5342748
-206466348 -6447384
-206454728 -6809307
-206416737 -7877319
-206365268 -9126757
-206352649 -9407755
-206350222 -9460834
-206342491 -9627970
-206253359 -11378633
-206140...

output:

-1
106
642 778 748 44 965 103 823 105 431 307 441 796 690 726 267 447 797 806 560 775 397 890 114 807 410 842 985 730 813 125 232 912 426 205 866 812 39 970 876 949 895 416 894 957 1 830 612 803 24 178 281 903 400 207 877 194 46 577 543 227 716 147 969 344 422 525 975 451 783 249 113 789 524 818 42 ...

result:

ok 100 cases.

Test #4:

score: 0
Accepted
time: 550ms
memory: 40120kb

input:

100
1000 1000
-208687104 -518935
-208658071 -3519412
-208647420 -4102540
-208612602 -5599926
-208458791 -9772885
-208145426 -15035235
-207718591 -20088894
-207636408 -20921257
-207598046 -21298548
-207567860 -21590745
-207181177 -25030716
-206899863 -27258453
-206707452 -28681109
-206631693 -2922191...

output:

461
291 582 93 372 655 584 342 600 587 989 837 964 434 200 504 267 180 586 466 206 865 958 966 576 614 218 308 351 386 284 343 278 691 671 255 481 727 734 454 598 816 974 442 426 544 610 990 355 779 971 568 456 543 567 333 464 85 904 114 772 714 188 13 888 60 54 350 946 203 302 61 364 603 385 394 77...

result:

ok 100 cases.