QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#674011 | #5415. Ropeway | yumingsk# | WA | 2ms | 13812kb | C++20 | 2.8kb | 2024-10-25 13:09:26 | 2024-10-25 13:09:26 |
Judging History
answer
#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";
using namespace std;
const int Mod = 998244353;
const int N = 5e5 + 10;
using ll = long long;
ll n, k, a[N], b[N], lf[N], L, R, que[N], rf[N], p, v, q, fir, minnn, minn, c[N];
char ch;
ll min(ll a, ll b) { return a < b ? a : b; }
ll max(ll a, ll b) { return a > b ? a : b; }
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
{
cin >> ch;
b[i] = 0;
if (ch == '1')
b[i] = i;
else
b[i] = b[i - 1];
}
for (int i = n; i > 0; i--)
if (b[i] == i)
c[i] = i;
else
c[i] = c[i + 1];
b[0] = c[0] = 0;
b[n + 1] = c[n + 1] = n + 1;
a[0] = a[n + 1] = 0;
rf[n + 1] = 0;
lf[0] = 0;
L = 0;
R = 1;
que[1] = 0;
for (int i = 1; i <= n + 1; i++)
{
while (que[L + 1] <= i - k - 1)
L++;
lf[i] = lf[que[L + 1]] + a[i];
if (b[i] != i)
{
while (R > L && lf[i] < lf[que[R]])
R--;
que[++R] = i;
}
else
{
que[++R] = i;
L = R - 1;
}
}
L = 0;
R = 1;
que[1] = n + 1;
for (int i = n; i >= 0; i--)
{
while (que[L + 1] >= i + k + 1)
L++;
rf[i] = rf[que[L + 1]] + a[i];
if (b[i] != i)
{
while (R > L && rf[i] < rf[que[R]])
R--;
que[++R] = i;
}
else
{
que[++R] = i;
L = R - 1;
}
}
cin >> q;
while (q--)
{
cin >> p >> v;
if (b[p] == p)
{
cout << lf[n + 1] - a[p] + v << '\n';
continue;
}
minn = lf[p] + rf[p] - 2 * a[p] + v;
fir = max(b[p], p - k + 1);
minnn = L_INF;
for (int i = p + 1; i < fir + k && i <= c[p]; i++)
minnn = min(minnn, rf[i]);
for (int i = fir; i < p; i++)
{
if (i + k <= c[p])
minnn = min(minnn, rf[i + k]);
minn = min(minn, lf[i] + minnn);
}
cout << minn << '\n';
}
}
int main()
{
IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
clock_t start_time = clock();
#endif
int t = 1;
cin >> t;
while (t--)
{
solve();
}
#ifndef ONLINE_JUDGE
cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11744kb
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: 13812kb
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 1685424960 ...
result:
wrong answer 33rd numbers differ - expected: '849950346', found: '1685424960'