QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628172#5415. RopewayNanamiWA 3ms24396kbC++172.6kb2024-10-10 18:59:382024-10-10 18:59:39

Judging History

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

  • [2024-10-10 18:59:39]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:24396kb
  • [2024-10-10 18:59:38]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 5e5 + 10, INF = 0x3f3f3f3f;

int T, n, m, k, hd, ed;
int a[N], q[N], q2[N], fr[N], x[N], v[N], id[N];
int f[N], tf[N], g[N], ans[N];
char s[N];

bool cmp(int a, int b) {
    return x[a] < x[b];
}

signed main() {
    cin >> T;
    while(T --) {
        cin >> n >> k;
        for(int i = 1; i <= n; i ++) cin >> a[i];

        cin >> s + 1;

        a[0] = a[n + 1] = f[0] = 0;
        q[hd = ed = 1] = 0;

        for(int i = 1; i <= n + 1; i ++) {
            while(q[hd] < i - k) hd ++;
            f[i] = f[q[hd]] + a[i];

            if(s[i] == '1') q[hd = ed = 1] = i;
            else {
                while(ed >= hd && f[q[ed]] >= f[i]) ed --;
                q[++ ed] = i;
            }
        }

        q[hd = ed = 1] = n + 1;
        fr[n + 1] = n + 1;
        g[n + 1] = 0;

        for(int i = n; i >= 0; i --) {
            while(q[hd] > i + k) hd ++;

            g[i] = g[q[hd]] + a[i];
            fr[i] = q[hd];

            if(s[i] == '1') q[hd = ed = 1] = i;
            else {
                while(ed >= hd && g[q[ed]] >= g[i]) ed --;
                q[++ ed] = i;
            }
        }

        cin >> m;
        for (int i = 1; i <= m; ++i)    scanf("%d%d", &x[i], &v[i]), id[i] = i, ans[i] = INF;
        sort(id + 1, id + m + 1, cmp);
        q[hd = ed = 1] = 0;
        int cur = 1;
        for (int i = 1; i <= n; ++i) {
            while (q[hd] < i - k)   ++hd;
            while (x[id[cur]] == i && cur <= m) {
                int hd2 = hd, ed2 = ed, t = a[i];
                a[i] = v[id[cur]];
                for (int j = hd; j <= ed; ++j)  q2[j] = q[j];
                int mx = min(i + k, n + 1);
                for (int j = i; j <= mx; ++j) {
                    while (q2[hd2] < j - k)   ++hd2;
                    tf[j] = tf[q2[hd2]] + a[j];
                    ans[id[cur]] = min(ans[id[cur]], tf[j] + g[fr[j]]);
                    if (s[j] == '1')    q2[hd2 = ed2 = 1] = j;
                    else {
                        while (ed2 >= hd2 && tf[q2[ed2]] > tf[j]) --ed2;
                        q2[++ed2] = j;
                    }
                }
                a[i] = t;
                ++cur;
            }
            tf[i] = tf[q[hd]] + a[i];
            if (s[i] == '1')    q[hd = ed = 1] = i;
            else {
                while (ed >= hd && f[q[ed]] > f[i]) --ed;
                q[++ed] = i;
            }
        }
        for (int i = 1; i <= m; ++i)    printf("%lld\n", ans[i]);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 24396kb

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: 3ms
memory: 22344kb

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:

1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
1061109567
470735446
470735446
211705888
564509290
715543137
470735446
470735446
18
19
19
19
20
19
54
849950346
8...

result:

wrong answer 1st numbers differ - expected: '2472886431', found: '1061109567'