QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520147 | #5074. Vision Test | zhouhuanyi | WA | 56ms | 11184kb | C++14 | 4.3kb | 2024-08-15 11:06:09 | 2024-08-15 11:06:10 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#define N 100000
using namespace std;
const int inf=(int)(1e9);
const long long INF=(long long)(1e18);
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int gcd(int x,int y)
{
if (!y) return x;
return gcd(y,x%y);
}
struct frac
{
int a,b;
bool operator < (const frac &t)const
{
return 1ll*a*t.b<1ll*b*t.a;
}
bool operator <= (const frac &t)const
{
return 1ll*a*t.b<=1ll*b*t.a;
}
};
frac L,R,delta[N+1],delta2[N+1];
frac operator + (frac x,frac y)
{
return (frac){x.a+y.a,x.b+y.b};
}
frac operator * (frac x,int d)
{
return (frac){x.a*d,x.b*d};
}
frac lca(frac x,frac y)
{
if (x.a==-1) return (frac){0,1};
frac l=(frac){0,1},r=(frac){1,0},res;
int d;
while (1)
{
res=l+r;
if (y<=res)
{
d=1;
for (int i=log(inf/max(l.a,l.b))/log(2);i>=0;--i)
if (d+(1<<i)<=inf/max(l.a,l.b)&&y<=l*(d+(1<<i))+r)
d+=(1<<i);
r=l*d+r;
}
else if (res<=x)
{
d=1;
for (int i=log(inf/max(r.a,r.b))/log(2);i>=0;--i)
if (d+(1<<i)<=inf/max(r.a,r.b)&&l+r*(d+(1<<i))<=x)
d+=(1<<i);
l=l+r*d;
}
else break;
}
return res;
}
struct reads
{
int num,l,r;
};
int T,n,q,sz,top,top2,lg[N+1],A[N+1],C[N+1],X[N+1],dque[N+1],dque2[N+1];
long long maxn,B[N+1];
vector<int>sp[N+1];
vector<int>tp[N+1];
bool check(int x,int y,int z)
{
return 1ll*(X[y]-X[x])*(z-x)>=1ll*(X[z]-X[x])*(y-x);
}
bool check2(int x,int y,int z)
{
return 1ll*(X[y]-X[x])*(z-x)<=1ll*(X[z]-X[x])*(y-x);
}
void solve(int l,int r,vector<reads>p)
{
if (p.empty()) return;
int mid=(l+r)>>1;
frac maxn=(frac){-1,1},minn=(frac){1,0},d;
vector<reads>pA;
vector<reads>pB;
top=top2=0;
for (int i=l;i<=r;++i) sp[i].clear(),sp[i].shrink_to_fit(),tp[i].clear(),tp[i].shrink_to_fit();
for (int i=mid;i>=l;--i)
{
while (top>=2&&check(i,dque[top],dque[top-1])) top--;
while (top2>=2&&check2(i,dque[top2],dque[top2-1])) top2--;
for (int j=1;j<=top2;++j) maxn=max(maxn,(frac){X[dque2[j]]-X[i]-1,dque2[j]-i});
for (int j=1;j<=top;++j) minn=min(minn,(frac){X[dque[j]]-X[i]+1,dque[j]-i});
delta[i]=maxn,delta2[i]=minn,dque[++top]=dque2[++top2]=i;
for (int j=1;j<=top;++j) sp[i].push_back(dque[j]);
for (int j=1;j<=top2;++j) tp[i].push_back(dque2[j]);
}
top=top2=0,maxn=(frac){-1,1},minn=(frac){1,0};
for (int i=mid+1;i<=r;++i)
{
while (top>=2&&check(dque[top-1],dque[top],i)) top--;
while (top2>=2&&check2(dque2[top2-1],dque2[top],i)) top2--;
for (int j=1;j<=top;++j) maxn=max(maxn,(frac){X[i]-X[dque[j]]-1,i-dque[j]});
for (int j=1;j<=top2;++j) minn=min(minn,(frac){X[i]-X[dque2[j]]+1,i-dque2[j]});
delta[i]=maxn,delta2[i]=minn,dque[++top]=dque2[++top2]=i;
for (int j=top;j>=1;--j) sp[i].push_back(dque[j]);
for (int j=top2;j>=1;--j) tp[i].push_back(dque2[j]);
}
for (int i=0;i<p.size();++i)
{
if (p[i].r<=mid) pA.push_back(p[i]);
else if (p[i].l>=mid+1) pB.push_back(p[i]);
else
{
maxn=max(delta[p[i].l],delta[p[i].r]),minn=min(delta2[p[i].l],delta2[p[i].r]);
for (int j=0;j<sp[p[i].l].size();++j)
for (int k=0;k<tp[p[i].r].size();++k)
maxn=max(maxn,(frac){X[tp[p[i].r][k]]-X[sp[p[i].l][j]]-1,tp[p[i].r][k]-sp[p[i].l][j]});
for (int j=0;j<tp[p[i].l].size();++j)
for (int k=0;k<sp[p[i].r].size();++k)
minn=min(minn,(frac){X[sp[p[i].r][k]]-X[tp[p[i].l][j]]+1,sp[p[i].r][k]-tp[p[i].l][j]});
d=lca(maxn,minn),A[p[i].num]=d.a,C[p[i].num]=d.b,B[p[i].num]=0;
for (int j=0;j<tp[p[i].l].size();++j) B[p[i].num]=max(B[p[i].num],1ll*X[tp[p[i].l][j]]*d.b-1ll*(tp[p[i].l][j]-p[i].l)*d.a);
for (int j=0;j<tp[p[i].r].size();++j) B[p[i].num]=max(B[p[i].num],1ll*X[tp[p[i].r][j]]*d.b-1ll*(tp[p[i].r][j]-p[i].l)*d.a);
}
}
solve(l,mid,pA),solve(mid+1,r,pB);
return;
}
int main()
{
int l,r;
vector<reads>p;
for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
T=read();
while (T--)
{
n=read(),top=top2=0,p.clear();
for (int i=1;i<=n;++i) X[i]=read();
q=read();
for (int i=1;i<=q;++i)
{
l=read(),r=read();
if (l==r) A[i]=0,B[i]=X[l],C[i]=1;
else p.push_back((reads){i,l,r});
}
solve(1,n,p);
for (int i=1;i<=q;++i) printf("%d %lld %d\n",A[i],B[i],C[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9916kb
input:
3 5 1 1 2 2 2 4 1 5 1 1 3 5 2 3 5 1 2 3 4 6 3 1 5 2 4 3 5 3 0 3 5 1 1 3
output:
1 4 3 0 1 1 0 2 1 1 1 1 5 4 4 1 2 1 3 6 2 5 1 2
result:
ok 24 numbers
Test #2:
score: 0
Accepted
time: 48ms
memory: 11184kb
input:
20000 5 216985264 261263380 305541495 349819610 394097726 5 2 3 3 5 1 2 1 1 5 5 5 375382625 514874812 654366999 793859186 933351373 5 3 5 2 5 2 4 4 4 1 2 5 4203556 117160178 230116801 343073423 456030045 5 2 5 1 1 3 4 2 4 5 5 5 925374406 933391410 941408414 949425418 957442422 5 3 4 5 5 2 3 1 3 4 5 ...
output:
44278115 261263380 1 88556231 611082990 2 44278116 216985264 1 0 216985264 1 0 394097726 1 139492187 654366999 1 139492187 514874812 1 139492187 514874812 1 0 793859186 1 139492187 375382625 1 338869867 351480536 3 0 4203556 1 112956622 230116801 1 225913245 234320357 2 0 456030045 1 8017004 9414084...
result:
ok 300000 numbers
Test #3:
score: 0
Accepted
time: 51ms
memory: 10276kb
input:
20000 5 663398562 733306156 803213750 873121344 943028938 5 1 2 3 3 2 4 1 1 3 5 5 90107073 216544148 342981224 469418300 595855376 5 1 1 5 5 2 3 3 5 3 4 5 578795185 603695239 628595293 653495347 678395402 5 4 5 1 4 4 4 4 5 2 4 5 99770585 174616657 249462729 324308801 399154873 5 1 2 4 5 1 4 1 5 1 4 ...
output:
69907594 663398562 1 0 803213750 1 69907594 733306156 1 0 663398562 1 69907594 803213750 1 0 90107073 1 0 595855376 1 126437076 216544148 1 126437076 342981224 1 126437076 342981224 1 24900055 653495347 1 24900054 578795185 1 0 653495347 1 24900055 653495347 1 24900054 603695239 1 74846072 99770585 ...
result:
ok 300000 numbers
Test #4:
score: -100
Wrong Answer
time: 56ms
memory: 10572kb
input:
10000 10 34013891 48852155 63690419 78528682 93366946 108205209 123043473 137881737 152720000 167558264 10 1 8 6 9 7 7 2 6 2 3 8 10 5 7 3 8 10 10 5 6 10 65005189 120529926 176054663 231579399 287104136 342628873 398153610 453678347 509203084 564727820 10 7 10 3 4 8 9 6 9 3 7 4 6 5 6 2 8 1 6 2 5 10 2...
output:
44514791 102041674 3 44514791 324615629 3 0 123043473 1 29676527 97704311 2 14838264 48852155 1 29676527 275763474 2 29676527 186733892 2 74191318 318452095 5 0 167558264 1 14838263 93366946 1 166574210 1194460832 3 55524736 176054663 1 55524737 453678347 1 55524737 342628873 1 222098947 704218652 4...
result:
wrong answer 1st numbers differ - expected: '74191318', found: '44514791'