QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#611369 | #5415. Ropeway | zqx | WA | 3ms | 11752kb | C++23 | 2.5kb | 2024-10-04 20:41:19 | 2024-10-04 20:41:20 |
Judging History
answer
#include<bits/stdc++.h>
#define AC return 0;
#define int long long
#define pii pair<int,int>
#define all(tar) tar.begian(),tar.end()
const int maxx=2e5+5;
const int mod=998244353;
using namespace std;
int n,m,t;
int a[maxx];
int pre[maxx];
int be[maxx];
string s;
int st[maxx];
int dppre[maxx],dpbe[maxx];
int sum=0;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
cin>>s;
s="1"+s+"1";
int head=0,tail=1,sum=0;
st[++head]=0;
be[n+1]=pre[0]=0;
for(int i=1;i<=n;i++){
if(s[i]=='1')sum+=a[i];
}
for(int i=1;i<=n+1;i++){
while(head<=tail&&i-st[head]>m){
++head;
}
pre[i]=pre[st[head]];
if(s[i]=='0')pre[i]+=a[i];
while(head<=tail&&pre[i]<=pre[st[tail]])--tail;
st[++tail]=i;
}
head=0,tail=1;
st[++head]=n+1;
for(int i=n;i>=0;i--){
while(head<tail&&st[head]-i>m)++head;
be[i]=be[st[head]];
if(s[i]=='0')be[i]+=a[i];
while(head<=tail&&be[i]<=be[st[tail]])--tail;
st[++tail]=i;
}
int q;
cin>>q;
while(q--){
int pos,v;
cin>>pos>>v;
if(s[pos]=='0'){
swap(v,a[pos]);
}else {
sum-=a[pos];
sum+=v;
}
int l=max(0ll,pos-2*m-1);
int r=min(n+1,pos+2*m+1);
head=0,tail=1;
st[++head]=l;
dppre[l]=pre[l];
for(int i=l+1;i<=r;i++){
while(head<=tail&&i-st[head]>m){
++head;
}
dppre[i]=dppre[st[head]];
if(s[i]=='0')dppre[i]+=a[i];
while(head<=tail&&dppre[i]<=dppre[st[tail]])--tail;
st[++tail]=i;
}
dpbe[r]=be[r];
head=0,tail=1;
st[++head]=r;
for(int i=r-1;i>=l;i--){
while(head<tail&&st[head]-i>m)++head;
dpbe[i]=dpbe[st[head]];
if(s[i]=='0')dpbe[i]+=a[i];
while(head<=tail&&dpbe[i]<=dpbe[st[tail]])--tail;
st[++tail]=i;
}
int ans=1e18;
for(int i=l;i<=r;i++){
ans=min(ans,dppre[i]+dpbe[i]-a[i]*((s[i]-'0')^1)+sum);
}
cout<<ans<<'\n';
if(s[pos]=='0'){
swap(v,a[pos]);
continue;
}else {
sum+=a[pos];
sum-=v;
}
}
}
AC
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9780kb
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: 3ms
memory: 11752kb
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:
2474298712 2299111966 2796055445 2950534108 2417273966 2809026521 2285479513 2521569560 2521569560 2240907690 2577284958 2521569560 2766700195 2511807344 2521569560 2438434986 2669077215 2682112324 470735446 470735446 211705888 564509290 715543137 470735446 470735446 18 19 20 20 20 21 66 849950346 8...
result:
wrong answer 1st numbers differ - expected: '2472886431', found: '2474298712'