QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#782928#5415. RopewayAlicXWA 1ms12148kbC++141.9kb2024-11-25 22:14:352024-11-25 22:14:52

Judging History

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

  • [2024-11-25 22:14:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:12148kb
  • [2024-11-25 22:14:35]
  • 提交

answer

#include<bits/stdc++.h> 
#define int long long 
#define x first 
#define y second 
#define il inline 
#define em emplace 
#define eb emplace_back 
#define debug() puts("-----") 
using namespace std; 
typedef pair<int,int> pii; 
il int read(){ 
	int x=0,f=1; char ch=getchar(); 
	while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } 
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); 
	return x*f; 
} 
const int N=5e5+10; 
int n,k; 
int a[N]; 
bool st[N]; 
int f[N],g[N]; 
int q[N],hh,tt; 
il void solve(){ 
	n=read(),k=read(); int sum=0; 
	for(int i=1;i<=n;i++) a[i]=read(); 
	for(int i=1;i<=n;i++){ 
		char c; cin>>c; 
		if(c=='1') st[i]=true,sum+=a[i]; 
		else st[i]=false; 
	} f[0]=g[n+1]=0; 
	hh=tt=0,q[0]=0; 
	for(int i=1;i<=n;i++){ 
		while(hh<=tt&&i-q[hh]>k) hh++; 
		int val=a[i]; 
		if(st[i]) val=0; 
		f[i]=f[q[hh]]+val; 
		while(hh<=tt&&f[q[tt]]>=f[i]) tt--; 
		q[++tt]=i; 
	} hh=tt=0,q[0]=n+1; 
	for(int i=n;i>=1;i--){ 
		while(hh<=tt&&q[hh]-i>k) hh++; 
		int val=a[i]; 
		if(st[i]) val=0; 
		g[i]=g[q[hh]]+val; 
		while(hh<=tt&&g[q[tt]]>=g[i]) tt--; 
		q[++tt]=i; 
	} int Q=read(); 
	while(Q--){ 
		int x=read(),v=read(); 
		if(st[x]) sum-=a[x],sum+=v; 
		int L=max(0ll,x-k),R=min(n+1,x+k); 
		int ans=1e18,val=v; 
		if(st[x]) val=0; 
		int Min=1e18; 
		for(int i=L;i<x;i++) Min=min(Min,f[i]); 
		val+=Min,Min=1e18; 
		for(int i=x+1;i<=R;i++) Min=min(Min,g[i]); 
		ans=min(ans,Min+val+sum); 
		Min=1e18; 
		for(int i=max(0ll,x+1-k);i<x;i++){ 
			Min=min(Min,g[min(i+k,n+1)]); 
			ans=min(ans,f[i]+Min+sum); 
		} printf("%lld\n",ans); 
		if(st[x]) sum+=a[x],sum-=v; 
	} 
} 
signed main(){ 
	int T=read(); 
	while(T--) solve(); 
	return 0; 
} /*
1
10 3
5 10 7 100 4 3 12 5 100 1
0001000010
1
1 3

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
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 10036kb

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: 12148kb

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
2650202148
2417273966
2508694561
2285479513
2521569560
2521569560
2240907690
2577284958
2521569560
2766700195
2511807344
2521569560
2438434986
2669077215
2682112324
470735446
691602807
211705888
564509290
715543137
492281467
470735446
18
19
19
19
20
19
54
849950346
8...

result:

wrong answer 20th numbers differ - expected: '470735446', found: '691602807'