QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782806#5415. RopewayAlicXWA 2ms5896kbC++141.4kb2024-11-25 21:33:512024-11-25 21:33:51

Judging History

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

  • [2024-11-25 21:33:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5896kb
  • [2024-11-25 21:33:51]
  • 提交

answer

#include<bits/stdc++.h> 
#define ll 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=2e5+10; 
int n,k; 
ll f[N]; 
int a[N]; 
bool st[N]; 
int q[N],hh,tt;  
il void solve(){ 
	n=read(),k=read(); ll 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; 
	} int Q=read(); 
	while(Q--){ 
		int x=read(),v=read(); 
		int lst=a[x]; 
		if(st[x]) sum-=a[x],sum+=v; 
		else a[x]=v; 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; 
		} ll ans=1e18; 
		for(int i=n;i>=max(0,n-k+1);i--) ans=min(ans,f[i]+sum); 
		printf("%lld\n",ans); 
		if(!st[x]) a[x]=lst; 
	} 
} 
signed main(){ 
	int T=read(); 
	while(T--) solve(); 
	return 0; 
} /*
1
5 6
1 1 1 1 1
00100
1
3 100

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5832kb

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: 2ms
memory: 5896kb

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
2250428837
2524914722
2653547310
2549251716
2536376717
2300286670
2300286670
2300286670
2019624800
2075340198
2075340198
2320470833
2310708617
2310708617
2227574043
2375081698
2535624462
470735446
470735446
211705888
305479732
550287423
550287423
550287423
18
18
18
18
19
19
54
849950346
8...

result:

wrong answer 2nd numbers differ - expected: '2299111966', found: '2250428837'