QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227726 | #5415. Ropeway | xxcdsg | WA | 2ms | 7844kb | C++20 | 1.7kb | 2023-10-27 22:10:12 | 2023-10-27 22:10:12 |
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;
int q;cin >> q;
for(int i = 1;i <= q;i++){
int p,v;cin >> p >> v;
if(s[p] == '1'){
cout << sufdp[0] + v - a[p] << '\n';
}else{
ll ans = sufdp[p] + predp[p] + v - a[p] * 2;
ll mi = sufdp[p + 1];
int j = p + 2;
for(int ii = max(0ll,p - k + 1);ii <= p - 1;ii++){
while(j <= n + 1 && j - ii <= k) mi = min(sufdp[j],mi),j++;
ans = min(predp[ii] + mi,ans);
}
cout << ans << '\n';
}
}
}
signed main(){
IOS
int t = 1;cin >> t;
while(t--){
test();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7844kb
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: 7584kb
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 1765265336 2318835744 2240907690 2577284958 2318835744 2766700195 2511807344 2318835744 2438434986 2669077215 2682112324 341886459 470735446 211705888 564509290 715543137 470735446 146144035 18 19 19 19 20 15 54 15465560 15...
result:
wrong answer 8th numbers differ - expected: '2521569560', found: '1765265336'