QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#547101 | #5415. Ropeway | Sunnyzbh | WA | 2ms | 11832kb | C++20 | 1.2kb | 2024-09-04 18:10:38 | 2024-09-04 18:10:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=5e5+5;
int n,k,q[N],h,t;
char s[N];
ll f[N],g[N],a[N],c[N];
void init(ll* f){
h=1,t=0;
f[0]=0;
q[++t]=0;
for(int i=1;i<=n+1;i++){
while(i-q[h]>k) h++;
f[i]=f[q[h]]+a[i];
if(s[i]=='1') h=1,t=0;
while(h<=t&&f[q[t]]>=f[i]) t--;
q[++t]=i;
}
}
ll dp(int x,int y){
int t=a[x];a[x]=y;
ll ret=1e18;
h=1,t=0;
for(int i=k;i>0;i--) if(x-i>=0){
if(s[x-i]=='1') h=1,t=0;
while(h<=t&&q[t]>=f[x-i]) t--;
q[++t]=x-i;c[x-i]=f[x-i];
}
for(int i=x;i<x+k&&i<=n+1;i++){
while(q[h]<i-k) h++;
c[i]=c[q[h]]+a[i];
ret=min(ret,c[i]+g[i]);
if(s[i]=='1') h=1,t=0;
while(h<=t&&c[q[t]]>=c[i]) t--;
q[++t]=i;
}
a[x]=t;
return ret;
}
void solve(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
a[n+1]=0;
for(int i=1;i<=n;i++) cin>>s[i];
init(f);
reverse(a+1,a+n+1);reverse(s+1,s+n+1);
init(g);reverse(a+1,a+n+1),reverse(s+1,s+n+1);
reverse(g,g+n+2);
for(int i=1;i<=n;i++) g[i]-=a[i];
int q;cin>>q;
while(q--){
int x,y;cin>>x>>y;
cout<<dp(x,y)<<'\n';
}
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int t;cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11756kb
input:
3 10 3 5 10 7 100 4 3 12 5 100 1 0001000010 2 2 3 6 15 5 6 1 1 1 1 1 00000 1 3 100 5 6 1 1 1 1 1 00100 1 3 100
output:
206 214 0 100
result:
ok 4 number(s): "206 214 0 100"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 11832kb
input:
500 19 6 285203460 203149294 175739375 211384407 323087820 336418462 114884618 61054702 243946442 19599175 51974474 285317523 222489944 26675167 300331960 1412281 324105264 33722550 169011266 1111111110110100011 18 3 127056246 5 100630226 14 301161052 2 331781882 5 218792226 2 190274295 12 49227476 ...
output:
2472886431 2299111966 2796055445 2151374956 2417273966 2009867369 2258804347 2209576874 2521569560 1538931205 2265292272 2521569560 2454707509 1809830859 2521569560 2142514073 2087838782 2682112324 470735446 470735446 211705888 564509290 390951727 470735446 146144036 18 18 18 18 20 19 54 849950346 8...
result:
wrong answer 4th numbers differ - expected: '2650202148', found: '2151374956'