QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317791 | #5415. Ropeway | duckindog | WA | 1ms | 10048kb | C++14 | 2.1kb | 2024-01-29 18:30:02 | 2024-01-29 18:30:03 |
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];
int q;
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;
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);
}
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];
dq.clear();
for (int i = max(0ll, p - k); 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 mi = 1e9;
int it = dq.back();
for (int i = it + 1; i <= min(n + 1, it + k); ++i) {
mi = min(mi, g[i]);
if (s[i] == '1') {
mi = g[i];
break;
}
}
cout << f[it] + mi << "\n";
for (int i = p; i <= min(n, p + k); ++i) f[i] = h[i];
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9692kb
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: 10048kb
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 2379061425 2417273966 2355715838 2559965398 2559965398 2521569560 2075053968 2615680796 2521569560 2805096033 2345953622 2521569560 2503190972 3008319086 2682112324 470735446 470735446 211705888 564509290 809316981 715543137 564509290 18 18 18 18 19 20 54 849950346 8...
result:
wrong answer 4th numbers differ - expected: '2650202148', found: '2379061425'