QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#329502 | #8257. Marathon Race 2 | unputdownable | 7 | 3ms | 7640kb | C++17 | 3.2kb | 2024-02-16 19:55:36 | 2024-02-16 19:55:36 |
answer
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#include <bits/stdc++.h>
// #define int long long
#define i64 long long
#define pii pair <int, int>
using namespace std;
inline int read(void) {
int x=0,sgn=1; char ch=getchar();
while(ch<48||57<ch) {if(ch==45)sgn=0;ch=getchar();}
while(47<ch&&ch<58) {x=x*10+ch-48; ch=getchar();}
return sgn? x:-x;
}
void write(int x) {
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
/*
write((Ans%p+p)%p); pls
*/
int n,m,L;
int a[500005];
int pos[1003],val[1003],f[1003][1003],preval[1003];
int resl[1003],resr[1003];
inline void chkmin(int&x,i64 y) { x=min((i64)x,y); }
inline int dis(int x,int y) { return pos[y]-pos[x]; }
inline void calc(void) {
for(int len=m-1; len>=1; --len) {
for(int l=1,r; l+len<=m; ++l) {
r=l+len; int hei=n-(preval[r]-preval[l-1])+1;
chkmin(f[l+1][r],f[l][r]+1ll*dis(l,l+1)*(hei+val[l]));
chkmin(f[r][l+1],f[l][r]+1ll*dis(l,r)*(hei+val[l]));
chkmin(f[r-1][l],f[r][l]+1ll*dis(r-1,r)*(hei+val[r]));
chkmin(f[l][r-1],f[r][l]+1ll*dis(l,r)*(hei+val[r]));
}
}
}
inline void work(int*A) {
for(int i=2; i<=m; ++i) A[i]=min((i64)A[i],A[i-1]+1ll*n*dis(i-1,i));
for(int i=m-1; i>=1; --i) A[i]=min((i64)A[i],A[i+1]+1ll*n*dis(i,i+1));
}
signed main() {
// freopen("localinput","r",stdin);
// freopen("localoutput","w",stdout);
n=read(); L=read(); a[0]=-1;
for(int i=1; i<=n; ++i) a[i]=read();
sort(a+1,a+n+1);
for(int i=1; i<=n; ++i) if(a[i]!=a[i-1]) {
pos[++m]=a[i]; val[m]=1;
if(m>=1000) {
int q=read();
for(int i=1; i<=q; ++i) puts("No");
return 0;
}
} else ++val[m];
for(int i=1; i<=m; ++i) preval[i]=preval[i-1]+val[i];
memset(f,0x3f,sizeof f);
f[1][m]=0; calc();
for(int i=1; i<=m; ++i) resl[i]=f[i][i];
memset(f,0x3f,sizeof f);
f[m][1]=0; calc();
for(int i=1; i<=m; ++i) resr[i]=f[i][i];
work(resl); work(resr);
int q=read();
for(int i=1,s,t,lim; i<=q; ++i) {
s=read(); t=read(); lim=read()-n;
i64 Ans;
if(t<=pos[1]) Ans=min(resl[1]+abs(s-pos[1]),resr[1]+abs(s-pos[m]))+1ll*(n+1)*(pos[1]-t);
else if(t>=pos[m]) Ans=min(resl[m]+abs(s-pos[1]),resr[m]+abs(s-pos[m]))+1ll*(n+1)*(t-pos[m]);
else {
int p=lower_bound(pos+1,pos+m+1,t)-pos;
int q=p-1;
assert(pos[q]<=t&&t<=pos[p]);
Ans=min(
min(resl[q]+abs(s-pos[1]),resr[q]+abs(s-pos[m]))+1ll*n*(t-pos[q]),
min(resl[p]+abs(s-pos[1]),resr[p]+abs(s-pos[m]))+1ll*n*(pos[p]-t)
);
}
// cerr<<Ans<<endl;
if(Ans>lim) puts("No");
else puts("Yes");
}
// fprintf(stderr,"%.4lf\n",1.0*clock()/CLOCKS_PER_SEC);
return 0;
}
/*
3 100
30 80 30
3
0 100 403
0 100 300
0 100 262
1 500000
166666
10
0 0 500000
0 0 499999
0 0 499998
0 0 499997
0 0 499996
0 0 5
0 0 4
0 0 3
0 0 2
0 0 1
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 3ms
memory: 7520kb
input:
1 500000 166666 10 0 0 500000 0 0 499999 0 0 499998 0 0 499997 0 0 499996 0 0 5 0 0 4 0 0 3 0 0 2 0 0 1
output:
Yes Yes No No No No No No No No
result:
ok 10 token(s): yes count is 2, no count is 8
Test #2:
score: 0
Accepted
time: 3ms
memory: 7636kb
input:
1 500000 0 10 0 0 500000 0 0 499999 0 0 499998 0 0 499997 0 0 499996 0 0 5 0 0 4 0 0 3 0 0 2 0 0 1
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
result:
ok 10 token(s): yes count is 10, no count is 0
Test #3:
score: 0
Accepted
time: 3ms
memory: 7524kb
input:
2 1 0 1 10 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10
output:
No No No No Yes Yes Yes Yes Yes Yes
result:
ok 10 token(s): yes count is 6, no count is 4
Test #4:
score: 0
Accepted
time: 0ms
memory: 7624kb
input:
3 1 0 0 1 10 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10
output:
No No No No No Yes Yes Yes Yes Yes
result:
ok 10 token(s): yes count is 5, no count is 5
Test #5:
score: 0
Accepted
time: 0ms
memory: 7640kb
input:
1 1 0 10 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
result:
ok 10 token(s): yes count is 10, no count is 0
Test #6:
score: 0
Accepted
time: 1ms
memory: 7560kb
input:
7 83382 35565 7347 27797 28072 31528 45377 43857 10 0 0 160004 0 0 224969 0 0 310304 0 0 354202 0 0 310303 0 0 493150 0 0 227687 0 0 448225 0 0 88396 0 0 155211
output:
No No Yes Yes No Yes No Yes No No
result:
ok 10 token(s): yes count is 4, no count is 6
Test #7:
score: 0
Accepted
time: 0ms
memory: 7640kb
input:
7 83382 35212 3869 11565 53219 2927 45479 40671 10 0 0 189926 0 0 419739 0 0 245553 0 0 110218 0 0 299387 0 0 1986 0 0 473275 0 0 195521 0 0 299386 0 0 246039
output:
No Yes No No Yes No Yes No No No
result:
ok 10 token(s): yes count is 3, no count is 7
Test #8:
score: 0
Accepted
time: 0ms
memory: 7620kb
input:
7 500000 6069 96930 28374 1275 53141 1423 6225 10 0 0 388080 0 0 73883 0 0 319880 0 0 141926 0 0 144641 0 0 67306 0 0 387304 0 0 387303 0 0 236649 0 0 130438
output:
Yes No No No No No Yes No No No
result:
ok 10 token(s): yes count is 2, no count is 8
Test #9:
score: 0
Accepted
time: 2ms
memory: 7576kb
input:
7 500000 22379 39203 896 17806 23724 7599 153 10 0 0 492328 0 0 190173 0 0 315557 0 0 190172 0 0 138962 0 0 298883 0 0 246521 0 0 194070 0 0 252592 0 0 418531
output:
Yes Yes Yes No No Yes Yes Yes Yes Yes
result:
ok 10 token(s): yes count is 8, no count is 2
Test #10:
score: 0
Accepted
time: 0ms
memory: 7552kb
input:
7 500000 0 0 0 0 0 0 0 10 0 0 124229 0 0 233729 0 0 306668 0 0 499999 0 0 220256 0 0 62117 0 0 115533 0 0 48137 0 0 160004 0 0 500000
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
result:
ok 10 token(s): yes count is 10, no count is 0
Test #11:
score: 0
Accepted
time: 0ms
memory: 7580kb
input:
7 498000 498000 498000 498000 498000 498000 498000 498000 10 0 0 261154 0 0 235539 0 0 224636 0 0 283789 0 0 500000 0 0 480913 0 0 326331 0 0 499999 0 0 61700 0 0 280564
output:
No No No No No No No No No No
result:
ok 10 token(s): yes count is 0, no count is 10
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #12:
score: 7
Accepted
time: 0ms
memory: 7556kb
input:
1 2 1 8 0 0 3 0 0 4 0 2 3 0 2 4 2 0 3 2 0 4 2 2 3 2 2 4
output:
No Yes No Yes No Yes No Yes
result:
ok 8 token(s): yes count is 4, no count is 4
Test #13:
score: 0
Accepted
time: 2ms
memory: 7556kb
input:
1 2 1 10 0 1 1 0 1 2 2 1 1 2 1 2 1 0 2 1 0 3 1 2 2 1 2 3 1 1 1 1 1 500000
output:
No Yes No Yes No Yes No Yes Yes Yes
result:
ok 10 token(s): yes count is 6, no count is 4
Test #14:
score: -7
Wrong Answer
time: 0ms
memory: 7584kb
input:
3 11 1 5 10 10 2 6 40 2 6 41 1 6 39 1 6 40 0 6 40 0 6 41 2 7 38 2 7 39 2 5 36 2 5 37
output:
Yes Yes Yes Yes Yes Yes Yes Yes No Yes
result:
wrong answer expected NO, found YES [1st token]
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%