QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262608#5415. Ropewayvp_accountWA 0ms9948kbC++141.5kb2023-11-23 20:47:032023-11-23 20:47:03

Judging History

你现在查看的是最新测评结果

  • [2023-11-23 20:47:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9948kb
  • [2023-11-23 20:47:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
constexpr int M=5e5+5;
int n,m,k,p,v;char s[M];
int a[M],q[M];LL f[M],F[M],g[M];
int read(){
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return x*f;
}
void solve(){
	n=read();m=read();
	for (int i=1;i<=n;i++) a[i]=read();
	scanf("%s",s+1);a[++n]=0;s[0]=s[n]='0';
	int head=0,tail=0;q[0]=0;
	for (int i=1;i<=n;i++){
		while (head<tail&&i-q[head]>m) head++;
		f[i]=f[q[head]]+a[i];
		if (s[i]^48) head=1,tail=0;
		while (head<tail&&f[q[tail]]>=f[i]) tail--;
		q[++tail]=i;
	} g[n]=0; q[head=tail=0]=n;
	for (int i=n-1;i;i--){
		while (head<tail&&q[head]-i>m) head++;
		g[i]=g[q[head]]+a[i];
		if (s[i]^48) head=1,tail=0;
		while (head<tail&&g[q[tail]]>=g[i]) tail--;
		q[++tail]=i;	
	}
	for (int i=1;i<=n;i++) F[i]=f[i];
	k=read();while (k--){
		p=read();v=read();LL ans=1ll<<60;
		swap(a[p],v);head=tail=0;
		for (int i=max(p-m,0);i<p;i++){
			while (head<tail&&i-q[head]>m) head++;
			if (s[i]^48) head=1,tail=0;
			while (head<tail&&f[q[tail]]>=f[i]) tail--;	
			q[++tail]=i;
		}
		for (int i=p;i<=min(p+m,n);i++){
			while (head<tail&&i-q[head]>m) head++;
			f[i]=f[q[head]]+a[i];
			if (s[i]^48) head=1,tail=0;
			while (head<tail&&f[q[tail]]>=f[i]) tail--;
			q[++tail]=i;
			if (i^p) ans=min(ans,f[i]+g[i]-a[i]);
		}
		for (int i=p;i<=min(p+m,n);i++) f[i]=F[i];
		printf("%lld\n",ans); swap(a[p],v);
	}
}
int main(){int T=read();
	while (T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9948kb

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:

411
214
0
101

result:

wrong answer 1st numbers differ - expected: '206', found: '411'