QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317817 | #5415. Ropeway | duckindog | WA | 2ms | 12092kb | C++14 | 2.8kb | 2024-01-29 19:44:59 | 2024-01-29 19:44:59 |
Judging History
answer
//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 10;
int n, k;
int a[N];
string s;
int f[N], g[N], h[N], j[N];
int q;
void harm() {
deque<int> dq;
dq.push_back(0);
for (int i = 1; i <= n; ++i) {
while (dq.size() && dq.back() < i - k) dq.pop_back();
f[i] = f[dq.back()] + a[i];
while (dq.size() && f[dq.front()] >= f[i]) dq.pop_front();
if (s[i] == '1') dq.clear();
dq.push_front(i);
}
dq.clear(); dq.push_back(n + 1);
for (int i = n; i >= 1; --i) {
while (dq.size() && dq.back() > i + k) dq.pop_back();
g[i] = g[dq.back()] + a[i];
while (dq.size() && g[dq.front()] >= g[i]) dq.pop_front();
if (s[i] == '1') dq.clear();
dq.push_front(i);
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
int test; cin >> test;
while (test--) {
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
a[n + 1] = f[n + 1] = g[n + 1] = 0;
cin >> s; s = '@' + s;
harm();
cin >> q;
while (q--) {
int p, v; cin >> p >> v;
int pre = a[p]; a[p] = v;
for (int i = p; i <= min(n, p + k); ++i) h[i] = f[i];
for (int i = min(n, p + k); i >= max(0ll, p - k - 1); --i) j[i] = g[i];
deque<int> dq; dq.push_back(min(n + 1, p + k + 1));
for (int i = min(n, p + k); i >= max(0ll, p - k - 1); --i) {
while (dq.size() && dq.back() > i + k) dq.pop_back();
g[i] = g[dq.back()] + a[i];
while (dq.size() && g[dq.front()] >= g[i]) dq.pop_front();
if (s[i] == '1') dq.clear();
dq.push_front(i);
}
dq.clear();
for (int i = max(0ll, p - k - 1); i < p; ++i) {
while (dq.size() && f[dq.front()] >= f[i]) dq.pop_front();
if (s[i] == '1') dq.clear();
dq.push_front(i);
}
for (int i = p; i <= min(n, p + k); ++i) {
while (dq.size() && dq.back() < i - k) dq.pop_back();
f[i] = f[dq.back()] + a[i];
while (dq.size() && f[dq.front()] >= f[i]) dq.pop_front();
if (s[i] == '1') dq.clear();
dq.push_front(i);
}
int answer = 1e15;
while (dq.size()) {
int it = dq.back(), mi = 1e15;
for (int i = it + 1; i <= min(n + 1, it + k + 1); ++i) {
mi = min(mi, g[i]);
if (s[i] == '1') break;
}
answer = min(answer, f[it] + mi);
dq.pop_back();
}
cout << answer << "\n";
for (int i = p; i <= min(n, p + k); ++i) f[i] = h[i];
for (int i = min(n, p + k); i >= max(0ll, p - k - 1); --i) g[i] = j[i];
a[p] = pre;
}
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 12088kb
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: 12092kb
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 54 849950346 8...
result:
wrong answer 116th numbers differ - expected: '4010332301', found: '3109815838'