QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#53504 | #10. 卡常数 | not_so_organic | 100 ✓ | 1414ms | 83424kb | C++ | 3.8kb | 2022-10-05 12:34:49 | 2022-10-05 12:34:51 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define enc(x) (x=Enc(a,b,las_res,x))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define db double
#define N 500000
#define dcmp(x,y) (sgn((x)-(y)))
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
inline db indb() { double x;scanf("%lf",&x);return (db)x; }
const db eps=0.00001;
inline db squ(db x) { return x*x; }
inline int sgn(db x) { return x<-eps?-1:x>eps; }
inline db F(db a,db b,db x) { return a*x-b*sin(x); }
inline db Enc(db a,db b,db las,db f,db L=-100,db R=100)
{
//return f;
db mid=(L+R)/2;
while(L+0.000000001<R)
{
db v=F(a,b,las*mid+1);
if(v<f) L=mid;else R=mid;
mid=(L+R)/2;
}
return (L+R)/2;
}
struct P{
static int cur_dim;db x[3];int id;
P(db _x=0,db _y=0,db _z=0,int _id=0) { x[0]=_x,x[1]=_y,x[2]=_z,id=_id; }
inline bool operator<(const P &p)const{return x[cur_dim]<p.x[cur_dim]; }
inline db dis2(const P &p)const
{
db ans=0;
rep(i,0,2) ans+=squ(x[i]-p.x[i]);
return ans;
}
}p[N],q[N],t,mx[N],mn[N],pp[N];
int P::cur_dim=0;int pos[N];
int nc,ch[N][2];
inline int push_up(int x)
{
int lc=ch[x][0],rc=ch[x][1];
rep(i,0,2)
{
if(lc) mx[x].x[i]=max(mx[x].x[i],mx[lc].x[i]),mn[x].x[i]=min(mn[x].x[i],mn[lc].x[i]);
if(rc) mx[x].x[i]=max(mx[x].x[i],mx[rc].x[i]),mn[x].x[i]=min(mn[x].x[i],mn[rc].x[i]);
}
return 0;
}
int build_cnt;
int build(int &rt,P *p,int l,int r,int dim=0)
{
if(l>r) return rt=0;
build_cnt++;
int mid=(l+r)/2;rt=++nc;
P::cur_dim=dim;
nth_element(p+l,p+mid,p+r+1);
pp[rt]=mx[rt]=mn[rt]=p[mid];
pos[p[mid].id]=rt;
build(ch[rt][0],p,l,mid-1,(dim+1)%3);
build(ch[rt][1],p,mid+1,r,(dim+1)%3);
return push_up(rt);
}
int ins_cnt;
int ins(int rt,P &q,int dim=0)
{
ins_cnt++;
int g,x;
if(q.x[dim]<pp[rt].x[dim]) g=0;else g=1;
if(ch[rt][g]) ins(ch[rt][g],q,(dim+1)%3);
else x=++nc,ch[rt][g]=x,pos[q.id]=x,pp[x]=mn[x]=mx[x]=q;
return push_up(rt);
}
inline int del(int x)
{
x=pos[x],pp[x].id=mn[x].id=mx[x].id=0;int lc=ch[x][0],rc=ch[x][1];
return 0;
}
inline db calc1(int x,P &p)
{
db ans=0;
rep(i,0,2) ans+=squ(max((db)0.0,mn[x].x[i]-p.x[i])+max((db)0.0,p.x[i]-mx[x].x[i]));
return ans;
}
inline db calc2(int x,P &p)
{
db ans=0;
rep(i,0,2) ans+=squ(max(mx[x].x[i]-p.x[i],p.x[i]-mn[x].x[i]));
return ans;
}
int ans;
int qry_cnt;
int query(int x,P &q,db r)
{
qry_cnt++;
if(!x||ans) return 0;
if(mn[x].id&&dcmp(q.dis2(pp[x]),r)==0) return ans=mn[x].id;
db dl=calc1(ch[x][0],q),dr=calc1(ch[x][1],q),d1=calc2(ch[x][0],q),d2=calc2(ch[x][1],q);
if(d1<d2)
{
if(dl<r+eps&&d1+eps>r) query(ch[x][0],q,r);
if(dr<r+eps&&d2+eps>r) query(ch[x][1],q,r);
}
else{
if(dr<r+eps&&d2+eps>r) query(ch[x][1],q,r);
if(dl<r+eps&&d1+eps>r) query(ch[x][0],q,r);
}
return 0;
}
int main()
{
int n,m,rt;scanf("%d%d",&n,&m);
db a=indb(),b=indb(),las_res=0.1;
for(int i=1;i<=n;p[i].id=i,i++)
for(int j=0;j<=2;j++) p[i].x[j]=indb();
for(int i=1;i<=n;i++) q[i]=p[i];build(rt,q,1,n);
while(m--)
{
int opt;scanf("%d",&opt);
if(opt==0)
{
db _i=indb(),x=indb(),y=indb(),z=indb();
enc(x),enc(y),enc(z);
_i=Enc(a,b,las_res,_i,1,n);
int id=(int)(_i+0.5);
del(id),p[id]=P(x,y,z,id),ins(rt,p[id]);
}
else{
db x=indb(),y=indb(),z=indb(),r=indb();
enc(x),enc(y),enc(z),t=P(x,y,z);
r=Enc(a,b,las_res,r,-1000,1000);
ans=0,query(rt,t,r*r),las_res=ans,printf("%d\n",ans);
}
}
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 19ms
memory: 82352kb
input:
1024 1024 3.2 0.1 -5.287133 6.295630 0.635575 3.439587 0.903770 -6.109870 3.659133 -0.479089 -4.140041 3.110743 0.597374 5.087570 3.104021 1.623165 -0.581646 2.345411 -1.247102 -7.224629 -3.519550 5.632687 4.824728 9.729180 -4.808827 4.668826 2.595880 1.924690 -1.475575 6.367650 0.413267 0.327768 -0...
output:
224 829 938 382 109 994 837 925 398 455 272 218 713 28 980 267 213 271 659 154 589 833 260 353 142 9 453 654 22 52 178 463 634 706 767 210 979 918 379 651 918 213 1007 642 548 124 322 156 867 974 5 887 555 559 523 922 227 122 658 916 416 671 424 460 724 526 13 4 592 151 951 493 662 10 950 509 581 93...
result:
ok 537 lines
Test #2:
score: 10
Accepted
time: 28ms
memory: 82300kb
input:
2048 2048 4.6 1.8 -30.324060 92.008512 -10.853952 -48.845284 54.212780 -60.249574 46.753448 -10.585702 66.362382 -11.311727 -94.305948 26.345946 -82.038593 -77.364538 -81.489496 42.342719 90.684519 69.918885 -50.333092 70.160445 15.454933 87.741081 -96.719655 38.652888 97.043464 58.620398 96.784225 ...
output:
379 547 694 274 405 1146 862 624 1790 1762 1053 1680 1235 1047 820 155 1157 225 468 1409 1882 1031 564 1518 561 693 1454 186 1573 280 492 160 1392 658 1090 669 84 1160 1397 281 718 1739 2045 714 436 1809 1769 1071 361 1223 1124 949 1814 442 1989 1336 183 1882 354 1427 648 1892 1970 1475 17 1855 1207...
result:
ok 1025 lines
Test #3:
score: 10
Accepted
time: 779ms
memory: 82724kb
input:
32768 32768 4.67 1.56 84.939218 -74.138709 50.938810 -67.042018 68.035250 -70.399291 52.800064 -71.292685 53.225961 -20.525715 33.451823 -65.068592 -25.520097 72.732868 69.097761 22.215709 -57.695300 -48.409886 35.446509 90.710192 -35.680885 -60.561016 -60.517046 -8.174342 -77.935361 -78.840195 95.3...
output:
30194 13684 10956 15758 174 19007 18158 23240 25026 17904 16643 30463 27249 3243 3546 10499 3366 7676 3122 1332 8214 2722 13901 4062 3706 15245 21820 18895 12238 31657 18242 28323 31341 3717 4207 15633 15292 23865 22362 29184 28802 29920 331 15141 28229 22957 12750 7559 20583 28938 28647 31100 12514...
result:
ok 32768 lines
Test #4:
score: 10
Accepted
time: 1414ms
memory: 82800kb
input:
32768 65536 3.95 0.18 14.056154 -30.150315 -77.588418 -98.232666 83.048322 36.852302 -16.963898 46.003829 -7.166507 -89.241244 -52.920748 -2.452281 -4.172825 -65.045528 -31.485175 -37.297909 50.213395 -21.809664 37.396983 34.533676 -29.251241 6.265591 78.434812 -14.170830 -86.676235 57.457258 -27.81...
output:
6818 11667 18789 19903 24629 26273 31179 23551 2792 6648 19713 7397 25796 11804 30273 26138 9184 24388 25836 13145 21833 31986 23407 6032 9558 1821 1439 27617 31451 27473 22124 26465 9438 12231 9406 24454 28202 17980 30341 2117 25526 23953 17065 9751 16346 23470 32478 2890 2603 4387 25200 29686 2350...
result:
ok 65536 lines
Test #5:
score: 10
Accepted
time: 1296ms
memory: 83340kb
input:
65536 65536 3.06 1.68 34.778462 22.247101 40.136088 22.245748 -43.219166 36.823722 65.928250 18.907994 -63.575439 95.838739 -77.231227 -1.609640 91.379763 4.112603 34.286943 -89.447280 2.078495 -46.947085 64.595702 -0.000307 -30.701957 78.546814 88.734645 -22.303236 26.093877 18.363883 -49.280232 -5...
output:
965 51532 14313 17256 36766 32794 36123 53973 43046 60200 16961 42820 18796 62531 59798 5846 63060 22453 50159 14557 39189 60480 12535 6080 41671 56075 38213 61477 25789 35310 21010 803 31397 13805 10669 43897 29456 8853 33549 23293 24557 56189 44711 285 5284 62335 8447 57794 10496 36434 34375 63444...
result:
ok 65536 lines
Test #6:
score: 10
Accepted
time: 587ms
memory: 82928kb
input:
32768 32768 4.25 3.98 16.261407 -3.579866 -79.159513 67.679089 -65.363455 78.768393 -36.872553 -27.651661 -15.273458 -20.905831 -25.161722 51.595933 -28.875568 -13.795375 39.138869 -19.301905 -29.707336 -57.471115 -53.548147 -33.829020 6.242839 26.216947 17.319888 -52.002265 -52.486606 -15.583705 -1...
output:
24478 11026 4116 29512 9951 27007 31104 16697 272 25060 14354 361 2835 10248 2196 11761 25261 19457 12412 29583 10162 2313 11956 31356 12666 14007 30646 17391 20034 27171 21355 18273 4381 17294 25741 21905 6812 12608 6624 2947 29946 15588 26467 12293 29728 15095 29175 23703 12023 9469 29626 20775 24...
result:
ok 16486 lines
Test #7:
score: 10
Accepted
time: 1266ms
memory: 83052kb
input:
32768 65536 2.28 2.08 -77.539108 9.020113 90.951933 -40.160423 -96.331979 80.089815 13.993026 -93.826031 -29.018021 92.664856 -33.089080 -0.657607 27.876505 22.826064 62.292361 -47.323183 -13.426563 -16.066616 81.711794 24.884818 -80.739379 18.337828 73.486039 71.076694 -98.992748 -17.695182 10.0227...
output:
8314 817 29663 22078 32598 14726 20716 4292 18454 25135 21244 15906 1350 3194 57 17179 7910 14960 18779 14505 19930 27810 22363 18653 3220 2562 11412 30399 8745 28613 31874 3893 30115 15461 27076 17864 23222 24525 23744 16663 30531 11444 8154 4925 8181 8888 539 1128 25039 20380 28158 31678 1544 2833...
result:
ok 32729 lines
Test #8:
score: 10
Accepted
time: 526ms
memory: 83292kb
input:
65536 32768 0.59 0.24 99.020814 -8.178256 99.557830 82.020375 18.019102 96.790487 48.083018 -78.152933 -19.288388 31.203678 95.123958 -66.973623 -83.940507 75.473022 -29.148823 4.254775 -90.825004 38.106763 64.658227 16.176496 -3.497318 -86.506375 -48.219119 -62.340429 64.209428 -40.757806 57.081505...
output:
28055 17574 59341 18595 11741 40334 52974 36632 30320 43060 27780 38454 1454 12749 60789 43230 55763 27464 16696 29394 37841 1878 62068 39368 4733 43278 42938 31784 52264 393 31980 39596 47733 18410 23169 31471 10041 33772 42838 20863 64543 2338 37677 1830 14709 40569 13229 40316 25381 36861 53405 5...
result:
ok 16469 lines
Test #9:
score: 10
Accepted
time: 1084ms
memory: 83424kb
input:
65536 65536 3.73 2.51 94.030160 -12.854842 -79.582087 99.708537 41.749589 -15.411580 -83.599242 -68.178210 9.579776 27.223008 66.351912 32.660029 -26.067712 -25.960860 -26.511404 71.015179 70.420405 -75.586624 58.776519 -10.874757 -42.559339 69.191366 -18.690434 41.428921 33.289206 92.676136 22.0591...
output:
32043 44897 5234 48758 38485 45399 17831 29941 20873 51166 21736 51634 56064 47866 32900 60637 44556 51267 64529 37570 63436 8100 47139 1824 33989 26745 39094 30066 10251 14021 19773 9816 10352 25219 7128 50887 30132 5362 46508 60651 57733 42918 7282 33355 31935 24715 39443 65293 32586 27809 27109 3...
result:
ok 32727 lines
Test #10:
score: 10
Accepted
time: 1062ms
memory: 83288kb
input:
65536 65536 2.54 0.67 78.221262 -73.957753 14.147439 39.328747 -22.396923 -70.131354 56.912390 70.724316 -30.562216 -12.046663 -10.503612 99.157809 -59.432409 28.684196 26.256164 13.311709 -35.565339 7.841181 60.081195 42.648279 33.916067 94.845938 -45.203322 -12.839457 10.129303 -43.764821 -2.62406...
output:
43349 2492 12336 11664 63943 27564 7922 57385 4573 4123 45077 44601 25768 52876 44596 47364 44386 58511 10547 20422 18092 10086 54785 53842 51182 54646 23966 14542 25838 16309 34735 57175 8204 13372 24640 5297 10871 48981 42948 46069 38459 22992 37418 15280 61928 28802 45321 14698 7522 49751 46454 4...
result:
ok 32844 lines