QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#474145 | #9127. Optimal Train Operation | PhantomThreshold# | WA | 4ms | 24256kb | C++20 | 2.0kb | 2024-07-12 16:20:23 | 2024-07-12 16:20:24 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define ll long long
#define int long long
using namespace std;
const int maxd = 20;
const int maxn = 510000;
int n;
int c[maxn],a[maxn];
int rmq[maxd][maxn];
void build()
{
for(int i=1;i<=n;i++) rmq[0][i]=c[i];
for(int d=1;(1<<d)<=n;d++)
{
for(int i=1;i+(1<<d)-1<=n;i++)
{
rmq[d][i]= max( rmq[d-1][i], rmq[d-1][i+(1<<(d-1))] );
}
}
}
int query(int l,int r)
{
int len=r-l+1;
int d= 31-__builtin_clz(len);
return max( rmq[d][l], rmq[d][r-(1<<d)+1] );
}
/*
int seg[maxn<<2];
void build(const int x,const int l,const int r)
{
if(l==r)
{
seg[x]=c[l];
return;
}
int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
build(lc,l,mid); build(rc,mid+1,r);
seg[x]=max(seg[lc],seg[rc]);
}
int lx,rx;
int query(const int x,const int l,const int r)
{
if(rx<l||r<lx) return -1;
if(lx<=l&&r<=rx) return seg[x];
int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
return max(query(lc,l,mid),query(rc,mid+1,r));
}*/
ll f[maxn];
int q[maxn],qc[maxn],head,tail;
int calc(int i,int j)
{
int l=j+1,r=n;
while(l<=r)
{
int mid=(l+r)>>1;
if( f[i] + query(i+1,mid)*(mid-i) >= f[j] + query(j+1,mid)*(mid-j) ) r=mid-1;
else l=mid+1;
}
return r+1;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
/*
cerr<<31-__builtin_clz(1)<<endl;
cerr<<31-__builtin_clz(2)<<endl;
cerr<<31-__builtin_clz(3)<<endl;
cerr<<31-__builtin_clz(4)<<endl;
*/
cin>>n;
for(int i=1;i<=n;i++) cin>>c[i];
build();
for(int i=1;i<n;i++) cin>>a[i];
a[0]=a[n]=0;
f[0]=0;
q[ head=tail=1 ]=0;
for(int i=1;i<=n;i++)
{
while(head<tail && i>=qc[head]) head++;
int j=q[head];
f[i]=f[j]+ a[i] + query(j+1,i)*(i-j);
q[++tail]=i;
while(head<tail)
{
if(f[q[tail-1]]>=f[q[tail]]) q[tail-1]=q[tail],tail--;
else
{
qc[tail-1]=calc(q[tail-1],q[tail]);
if(head+2<=tail && qc[tail-2]>=qc[tail-1]) q[tail-1]=q[tail],tail--;
else break;
}
}
}
cout<<f[n]<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18012kb
input:
4 3 1 4 1 5 9 2
output:
15
result:
ok "15"
Test #2:
score: 0
Accepted
time: 0ms
memory: 19976kb
input:
9 28 35 19 27 84 98 78 79 60 40 35 54 63 72 71 27 94
output:
682
result:
ok "682"
Test #3:
score: 0
Accepted
time: 0ms
memory: 18004kb
input:
7 476190629 262703497 211047202 971407775 628894325 731963982 822804784 877914575 602436426 24979445 861648772 623690081 433933447
output:
5339182432
result:
ok "5339182432"
Test #4:
score: 0
Accepted
time: 3ms
memory: 20064kb
input:
8 910286918 802329211 404539679 303238506 317063340 492686568 773361868 125660016 430302156 982631932 161735902 880895728 923078537 707723857 189330739
output:
6166732840
result:
ok "6166732840"
Test #5:
score: 0
Accepted
time: 0ms
memory: 17928kb
input:
5 191890310 576823355 782177068 404011431 818008580 839296263 462224593 492601449 384836991
output:
4069897043
result:
ok "4069897043"
Test #6:
score: 0
Accepted
time: 2ms
memory: 17936kb
input:
6 138996221 501899080 353195922 545531545 910748511 350034067 160449218 155374934 840594328 164163676 797829355
output:
3921700772
result:
ok "3921700772"
Test #7:
score: 0
Accepted
time: 0ms
memory: 15872kb
input:
2 824284691 533206504 470338674
output:
1648569382
result:
ok "1648569382"
Test #8:
score: -100
Wrong Answer
time: 4ms
memory: 24256kb
input:
4524 43 144 216 44 156 252 243 172 78 246 56 103 207 177 102 22 202 236 61 255 128 238 237 187 176 110 156 213 65 11 75 239 142 9 203 124 154 149 119 59 152 91 151 226 131 184 174 236 220 149 16 209 51 32 40 131 119 138 201 171 249 150 108 82 75 70 204 80 131 42 180 125 257 131 5 107 39 145 154 242 ...
output:
1128484
result:
wrong answer 1st words differ - expected: '892773', found: '1128484'