QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446455 | #8525. Mercenaries | grass8cow | ML | 160ms | 159572kb | C++14 | 2.9kb | 2024-06-17 10:52:54 | 2024-06-17 10:52:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
#define ll long long
struct no{
ll x,y;
no(){x=0,y=0;}
no(ll x_,ll y_){x=x_,y=y_;}
};
no operator - (const no &a,const no &b){return no(a.x-b.x,a.y-b.y);}
no operator + (const no &a,const no &b){return no(a.x+b.x,a.y+b.y);}
ll cro(no a,no b){return a.x*b.y-a.y*b.x;}
ll dot(no a,no b){return a.x*b.x+a.y*b.y;}
#define pb push_back
const int N=4e5+10;
struct qq{
int t;vector<no>A;
inline ll ask(no z){
if(A.empty())return 0;
while(t+1<A.size()&&dot(z,A[t])<=dot(z,A[t+1]))t++;
return dot(z,A[t]);
}
}F[N<<2],G[N<<2];
no sta[N<<2];int top;
qq bui(vector<no>e){
top=0;for(no o:e){
if(top&&sta[top].x==o.x){if(sta[top].y>=o.y)continue;top--;}
while(top>1&&cro(sta[top]-sta[top-1],o-sta[top-1])>=0)top--;
sta[++top]=o;
}
e.clear();
for(int i=1;i<=top;i++)e.pb(sta[i]);
qq p;p.A=e;p.t=0;return p;
}
qq operator + (const qq &x,const qq &y){
if(x.A.empty())return y;if(y.A.empty())return x;
vector<no>z;int i=0,j=0,ai=x.A.size(),bi=y.A.size();
while(i<ai||j<bi){
if(i<ai&&(j==bi||x.A[i].x<y.A[j].x))z.pb(x.A[i++]);
else z.pb(y.A[j++]);
}
return bui(z);
}
qq operator * (const qq &x,const qq &y){
if(x.A.empty())return y;if(y.A.empty())return x;
qq z;int ai=x.A.size(),bi=y.A.size(),i=0,j=0;z.t=0;
z.A.pb(x.A[0]+y.A[0]);
while(i+1<ai||j+1<bi){
if(i+1<ai&&(j+1==bi||cro(x.A[i+1]-x.A[i],y.A[j+1]-y.A[j])<=0))i++;
else j++;
z.A.pb(x.A[i]+y.A[j]);
}
return z;
}
void build(int p,int l,int r){
if(l==r){
int sz=1;
if(!(l&1))scanf("%d",&sz);
vector<no>a;
ll x,y;
while(sz--)scanf("%lld%lld",&x,&y),a.pb(no(x,y));
sort(a.begin(),a.end(),[&](no a,no b){return a.x<b.x;});
qq Z=bui(a);
if(l&1)F[p]=Z;else G[p]=Z;
return;
}
int mid=(l+r)>>1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
G[p]=G[p<<1]*G[p<<1|1];
F[p]=(F[p<<1]*G[p<<1|1])+F[p<<1|1];
}
ll ans[N];
struct que{
int id;
no a;int R;ll lim;
}o[N];
no fz;ll lk;int po;
void ask(int p,int l,int r,int x){
if(po!=-1)return;
if(x==r){
if(F[p].ask(fz)<lk){lk-=G[p].ask(fz);return;}
if(l==r){po=(l+1)/2;return;}
int mid=(l+r)>>1;
ask(p<<1|1,mid+1,r,r),ask(p<<1,l,mid,mid);
}
int mid=(l+r)>>1;
if(x<=mid)ask(p<<1,l,mid,x);
else ask(p<<1|1,mid+1,r,x),ask(p<<1,l,mid,x);
}
int main(){
scanf("%d",&n);build(1,1,n*2-1);
int q;scanf("%d",&q);ll x,y;
for(int i=1;i<=q;i++)scanf("%d%lld%lld%lld",&o[i].R,&x,&y,&o[i].lim),o[i].a=no(x,y),o[i].id=i;
sort(o+1,o+q+1,[&](que x,que y){return cro(x.a,y.a)<0;});
for(int i=1;i<=q;i++){
fz=o[i].a,lk=o[i].lim,po=-1;ask(1,1,n*2-1,o[i].R*2-1);
ans[o[i].id]=po;
}
for(int i=1;i<=q;i++)printf("%lld\n",ans[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 12ms
memory: 144628kb
input:
3 1 1 2 1 2 1 2 3 2 5 1 5 4 3 3 4 5 1 1 2 4 5 12 1 1 1 1 2 1 1 1 3 1 1 1 3 1 1 9 3 2 2 20 3 1 2 18 3 1 2 19 3 1 2 20 3 0 1 8 2 1 0 4 2 1 0 3 2 1 0 2
output:
1 2 3 3 2 2 1 -1 1 -1 2 2
result:
ok 12 numbers
Test #2:
score: 0
Accepted
time: 15ms
memory: 144420kb
input:
2 47 11 1 98 25 9 90 10 1 32 28 1811 2 17 44 4114 1 36 88 2661 2 79 33 3681 1 53 26 2778 2 59 20 2332 2 63 45 4616 2 72 11 10835 1 13 28 919 2 16 59 4445
output:
1 -1 -1 2 -1 1 2 1 1 2
result:
ok 10 numbers
Test #3:
score: 0
Accepted
time: 16ms
memory: 144464kb
input:
3 87 42 5 69 12 82 79 10 88 45 51 40 3 18 6 5 73 100 58 41 40 88 54 5 40 98 31 63 100 3 32 13 1811 1 51 21 5318 1 32 5 2994 2 77 51 19184 2 78 60 1763 1 10 1 913 1 22 51 4057 1 2 5 385 2 50 15 989 2 65 53 1488 1 49 82 7708 2 33 90 1133 1 23 33 3388 1 92 36 9516 3 39 61 10014 2 43 55 1103 2 48 38 127...
output:
3 1 1 1 2 -1 -1 -1 2 2 -1 2 -1 1 2 2 -1 3 2 2 3 1 1 1 -1 1 1 1 3 1 -1 1 -1 1 2 1 2 1 1 1 1 1 -1 1 -1 -1 1 1 -1 -1 1 1 2 1 1 -1 2 -1 1 1 1 1 3 1 2 3 2 2 1 1 -1 1 1 3 1 1 1 3 2 1 1 2 1 2 1 2 1 -1 -1 -1 1 2 1 1 -1 -1 1 3 2 2
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 160ms
memory: 159572kb
input:
2 309248041 338995438 500000 1235 4866 1931 3652 1921 258 545 587 3001 542 3074 1694 4944 206 3217 3135 2388 4791 1890 3281 3840 4614 4491 1339 4660 1708 2225 3199 736 1306 4175 4652 906 3509 2571 1578 50 981 402 4975 2730 2198 4546 3120 40 815 2492 518 2102 2651 1018 3996 1764 808 3934 4312 1981 40...
output:
2 1 -1 2 2 2 1 1 2 -1 2 2 1 1 2 1 2 2 1 2 2 1 -1 -1 1 -1 2 -1 1 2 1 1 1 1 -1 1 -1 -1 -1 1 2 2 1 1 1 2 -1 -1 1 -1 1 2 -1 1 2 1 2 2 -1 2 1 2 2 -1 2 2 -1 2 1 2 1 -1 -1 1 1 -1 2 1 2 2 1 1 1 1 2 2 -1 -1 1 2 2 -1 2 -1 -1 -1 1 2 1 1 2 2 1 -1 -1 2 2 2 1 -1 1 2 2 -1 1 -1 -1 -1 1 2 1 2 1 -1 -1 1 2 2 -1 2 2 2 ...
result:
ok 200000 numbers
Test #5:
score: -100
Memory Limit Exceeded
input:
200000 999999511 993051669 2 5000 5000 5000 5000 1000000000 1000000000 3 5000 5000 5000 5000 5000 5000 995868520 999999999 2 5000 5000 5000 5000 660478427 999992996 3 5000 5000 5000 5000 5000 5000 999999979 999999998 2 5000 5000 5000 5000 861450412 989532141 3 5000 5000 5000 5000 5000 5000 949861679...