QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93640#5415. RopewayweekWA 3ms9544kbC++141.8kb2023-04-01 22:57:302023-04-01 22:57:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-01 22:57:34]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9544kb
  • [2023-04-01 22:57:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N= 1e6 + 10;
const int INF = 1e18;
typedef pair<int,int> PII;
int n,m,K,a[N];
string s;
int f[N],g[N],h[N];


int dp(int x,int y)
{
	int old = a[x];
	a[x] = y;
	
	deque<PII> d;
	int L = max(1ll,x - K);
	int R = max(1ll,x - 1);
	if(x - K < 1) d.push_back({0,0});
	for(int i=L; i<=R; i++)
	{
		if(s[i - 1] == '1') d.clear();
		while(d.size() && d.back().first >= f[i]) d.pop_back();
		d.push_back({f[i],i});
	}
	int res = INF;
	for(int i=x; i<=x + K && i <= n + 1; i++)
	{
		while(d.front().second < i - K) d.pop_front();
		int now = d.front().first + a[i];
		res = min(res, now + g[i]);
		if(s[i - 1] == '1') d.clear();
		while(d.size() && d.back().first >= now) d.pop_back();
		d.push_back({now,i});
	}
	a[x] = old;
	return res;
}

void solve(){
	cin >> n >> K;
	for(int i=1; i<=n; i++) cin >> a[i];
	a[n + 1] = 0;
	g[n + 1] = 0;
	cin >> s;
	s = s + "1";
	deque<PII> d;
	d.push_back({0,0});
	for(int i=1; i<=n + 1; i++){
		while(d.front().second < i - K) d.pop_front();
		f[i] = d.front().first + a[i];
		if(s[i - 1] == '1') d.clear();
		while(d.size() && d.back().first >= f[i]) d.pop_back();
		d.push_back({f[i],i});
	}
	d.clear();
	d.push_back({0,n+1});
	for(int i=n; i>=1; i--){
		while(d.front().second > i + K) d.pop_front();
		g[i] = d.front().first + a[i];
		if(s[i - 1] == '1') d.clear();
		while(d.size() && d.back().first >= g[i]) d.pop_back();
		d.push_back({g[i],i});
	}
	for(int i=1; i<=n; i++) g[i] -= a[i];
	int q;
	cin >> q;
	while(q--)
	{
		int x,y;
		cin >> x >> y;
		cout << dp(x,y) << endl;
	}
	
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>> T;
	while(T--){
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 9544kb

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: 1ms
memory: 9512kb

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
2526111150
2577284958
2521569560
2766700195
2797010804
2521569560
2438434986
2669077215
2682112324
470735446
470735446
211705888
564509290
715543137
470735446
470735446
18
19
19
19
20
19
54
849950346
8...

result:

wrong answer 10th numbers differ - expected: '2240907690', found: '2526111150'