QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227747 | #5415. Ropeway | xxcdsg | WA | 2ms | 7728kb | C++20 | 1.9kb | 2023-10-27 22:30:43 | 2023-10-27 22:30:43 |
Judging History
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();
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);
if(s[i] == '1') break;
while(!qu.empty() && (ii - qu.front().first >= k || qu.front().second > sufdp[i])) qu.pop();
}
cout << ans << '\n';
}
}
}
signed main(){
IOS
int t = 1;cin >> t;
while(t--){
test();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7624kb
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: 7728kb
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 2712540666 2240907690 2577284958 2522981841 2766700195 2511807344 0 2438434986 2669077215 2682112324 341886459 470735446 211705888 564509290 715543137 470735446 470735446 18 19 19 19 20 19 54 15465560 157306493 1...
result:
wrong answer 9th numbers differ - expected: '2521569560', found: '2712540666'