QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#227753#5415. RopewayxxcdsgWA 1ms7916kbC++202.0kb2023-10-27 22:36:532023-10-27 22:36:53

Judging History

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

  • [2023-10-27 22:36:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7916kb
  • [2023-10-27 22:36:53]
  • 提交

answer

// xxc
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ll long long
#define int long long
#define debug(x) cout << #x << ' ' << x << endl;

const int N = 5e5 + 10;

ll predp[N],sufdp[N];//选中这个位置,需要最小的价值

int a[N];

void test(){
	int n,k;cin >> n >> k;
	for(int i = 1;i <= n;i++) cin >> a[i];
	string s;cin >> s;
	s = ' ' + s;
	
	queue<pair<int,ll>> qu;
	
	qu.push({0,0});
	predp[0] = 0;
	
	for(int i = 1;i <= n;i++){
		predp[i] = qu.front().second + a[i];
		if(s[i] == '1') while(!qu.empty()) qu.pop();
		while(!qu.empty() && (i - qu.front().first >= k || qu.front().second > predp[i])) qu.pop();
		qu.push({i,predp[i]});
	}
	
	predp[n + 1] = qu.front().second;
	while(!qu.empty()) qu.pop();
	
	qu.push({n + 1,0});
	sufdp[n + 1] = 0;
	
	for(int i = n;i >= 1;i--){
		sufdp[i] = qu.front().second + a[i];
		if(s[i] == '1') while(!qu.empty()) qu.pop();
		while(!qu.empty() && (qu.front().first - i >= k || qu.front().second > sufdp[i])) qu.pop();
		qu.push({i,sufdp[i]});
	}
	
	sufdp[0] = qu.front().second;
	while(!qu.empty()) qu.pop();
	
	int q;cin >> q;
	for(int i = 1;i <= q;i++){
		int p,v;cin >> p >> v;
		if(s[p] == '1'){
			cout << sufdp[p] + predp[p] + v - a[p] * 2 << '\n';
		}else{
			ll ans = sufdp[p] + predp[p] + v - a[p] * 2;
			for(int ii = max(p + 1 - k,0ll);ii <= p - 1;ii++){
				if(s[i] == '1') while(!qu.empty()) qu.pop();
				while(!qu.empty() && (ii - qu.front().first >= k || qu.front().second > predp[i])) qu.pop();
				qu.push({ii,predp[ii]});
			}
			for(int ii = p + 1;ii <= min(p - 1 + k,n + 1);ii++){
				ans = min(ans,sufdp[ii] + qu.front().second);
				ll tem = qu.front().second + a[ii];
				if(s[i] == '1') break;
				while(!qu.empty() && (ii - qu.front().first >= k || qu.front().second > tem)) qu.pop();
				qu.push({ii,tem});
			}
			cout << ans << '\n';
		}
	}
}

signed main(){
	IOS
	int t = 1;cin >> t;
	while(t--){
		test();
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7916kb

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
119
0
100

result:

wrong answer 2nd numbers differ - expected: '214', found: '119'