QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789602 | #5415. Ropeway | yugen | WA | 0ms | 3856kb | C++17 | 3.4kb | 2024-11-27 21:04:44 | 2024-11-27 21:04:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + 2);
for(int i = 1; i <= n; i ++ ) {
cin >> a[i];
}
string s;
cin >> s;
s = '1' + s + '1';
int q;
cin >> q;
vector<vector<pii> > que(n + 1);
for(int i = 1; i <= q; i ++ ) {
int pos, v;
cin >> pos >> v;
que[pos].push_back({v, i});
}
vector<ll> g(n + 2);
deque<ll> dq;
dq.push_back(n + 1);
for(int i = n; i >= 1; i -- ) {
while(dq.size() && i + k < dq.front()) {
// cout << '?' << i << ' ' << dq.front() << '\n';
dq.pop_front();
}
// cout << "h" << i << ' ' << dq.front() << '\n';
g[i] = g[dq.front()] + a[i];
while(dq.size() && g[i] <= g[dq.back()]) {
// cout << '!' << i << ' ' << dq.back() << '\n';
dq.pop_back();
}
if(s[i] == '1') {
while(dq.size()) dq.pop_front();
}
dq.push_back(i);
// cout << i << ' ' << g[i] << '\n';
}
// cout << '\n';
vector<ll> f(n + 2);
while(dq.size()) dq.pop_front();
dq.push_back(0);
vector<ll> ans(q + 1, 1e18);
for(int i = 1; i <= n; i ++ ) {
while(dq.size() && i - k > dq.front()) {
dq.pop_front();
}
int tmp = a[i];
for(auto [v, num] : que[i]) {
auto ndq = dq;
a[i] = v;
for(int j = i; j <= min(n + 1, i + k - 1); j ++ ) {
while(ndq.size() && j - k > ndq.front()) {
ndq.pop_front();
}
f[j] = f[ndq.front()] + a[j];
// cout << ndq.front() << ' ' << f[ndq.front()] << '\n';
// if(i != j) {
// cout << j << ' ' << f[j] << ' ' << g[j] << ' ' << a[j] << ' ' << f[j] + g[j] - a[j] << '\n';
// } else {
// cout << j << ' ' << f[j] << ' ' << g[j] << ' ' << tmp << ' ' << f[j] + g[j] - tmp << '\n';
// }
while(ndq.size() && f[j] <= f[ndq.back()]) {
// cout << '!' << j << ' ' << dq.back() << '\n';
ndq.pop_back();
}
if(s[j] == '1') {
while(ndq.size()) {
ndq.pop_front();
}
}
ndq.push_back(j);
if(j == i) {
ans[num] = min(ans[num], f[j] + g[j] - tmp);
} else {
ans[num] = min(ans[num], f[j] + g[j] - a[j]);
}
}
// cout << '\n';
}
a[i] = tmp;
f[i] = f[dq.front()] + a[i];
// if(que.size()) {
// for(int j = i + 1; j <= min(n + 1, i + k - 1); j ++ ) {
// f[j] = 0;
// }
// }
if(s[i] == '1') {
while(dq.size()) dq.pop_front();
}
dq.push_back(i);
}
for(int i = 1; i <= q; i ++ ) {
cout << ans[i] << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
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: 0ms
memory: 3572kb
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 2240907690 2577284958 2521569560 2766700195 2511807344 2521569560 2438434986 2669077215 2682112324 470735446 470735446 211705888 564509290 715543137 470735446 470735446 18 19 19 19 20 19 57 849950346 8...
result:
wrong answer 32nd numbers differ - expected: '54', found: '57'