QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673984#5415. Ropewayyumingsk#WA 2ms11840kbC++202.6kb2024-10-25 12:53:252024-10-25 12:53:25

Judging History

你现在查看的是最新测评结果

  • [2024-10-25 12:53:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11840kb
  • [2024-10-25 12:53:25]
  • 提交

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;
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];
    }
    b[0] = 0;
    b[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 = rf[p + 1];
        for (int i = p + 2; i < fir + k; i++)
            minnn = min(minnn, rf[i]);
        for (int i = fir; i < p; i++)
        {
            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: 9784kb

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: 11840kb

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
2184277563
2318835744
2240907690
2577284958
2318835744
2766700195
2511807344
2318835744
2438434986
2669077215
2682112324
341886459
470735446
211705888
564509290
715543137
470735446
146144035
18
19
19
19
20
15
54
849950346
8...

result:

wrong answer 8th numbers differ - expected: '2521569560', found: '2184277563'