QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#644203 | #5415. Ropeway | zyq_313 | RE | 2ms | 9776kb | C++14 | 2.0kb | 2024-10-16 11:46:15 | 2024-10-16 11:46:19 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int N = 1e6 + 10;
int n, k;
int a[N];
string op;
int query;
int f[N], g[N], tmp[N];
void solve(){
cin >> n >> k;
for (int i = 1; i <= n; i ++) cin >> a[i];
a[0] = 0, a[n + 1] = 0, tmp[0] = 0, tmp[n + 1] = 0;
int q[n + 10] = {0};
cin >> op;
op = " " + op;
int hh = 0, tt = -1;
int s = 0;
for (int i = 1; i <= n; i ++){
if (tt >= hh && i - k > q[hh]) hh ++;
if (i <= k) f[i] = s + a[i];
else f[i] = f[q[hh]] + a[i];
if (op[i] == '1') hh = 0, tt = -1;
while (tt >= hh && f[i] < f[q[tt]]) tt --;
q[++ tt] = i;
if (i <= k && op[i] == '1') s += a[i];
tmp[i] = 0;
}
hh = 0, tt = -1;
s = 0;
for (int i = n; i >= 1; i --){
if (tt >= hh && i + k < q[hh]) hh ++;
if (i >= n - k + 1) g[i] = s + a[i];
else g[i] = g[q[hh]] + a[i];
if (op[i] == '1') hh = 0, tt = -1;
while (tt >= hh && g[i] < g[q[tt]]) tt --;
q[++ tt] = i;
if (i >= n - k + 1 && op[i] == '1') s += a[i];
}
for (int i = 1; i <= n; i ++) g[i] -= a[i];
cin >> query;
hh = 0, tt = -1;
while (query --){
int x, val;
cin >> x >> val;
int old = a[x];
a[x] = val;
for (int i = k; i > 0; i --) if (x - i >= 0){
if (op[x - i] == '1') hh = 0, tt = -1;
while (tt >= hh && f[q[tt]] >= f[x - i]) tt --;
q[++ tt] = x - i;
tmp[x - i] = f[x - i];
}
int ans = 1e18;
for (int i = x; i < x + k && i <= n + 1; i ++){
if (tt >= hh && i - k > q[hh]) hh ++;
tmp[i] = tmp[q[hh]] + a[i];
ans = min(ans, tmp[i] + g[i]);
if (op[i] == '1') hh = 0, tt = -1;
while (tt >= hh && tmp[i] <= tmp[q[tt]]) tt --;
q[++ tt] = i;
}
cout << ans << endl;
a[x] = old;
}
for (int i = 1; i <= n; i ++) f[i] = g[i] = 0;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t --) solve();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9776kb
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
Runtime Error
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...