QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786320#5415. RopewayWaterSunWA 2ms12132kbC++142.1kb2024-11-26 21:05:352024-11-26 21:05:37

Judging History

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

  • [2024-11-26 21:05:37]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12132kb
  • [2024-11-26 21:05:35]
  • 提交

answer

#include <bits/stdc++.h>
#define re register
#define fst first
#define snd second
#define int long long
#define chmin(a,b) (a = min(a,b))

using namespace std;

typedef pair<int,int> pii;
const int N = 5e5 + 10;
const int inf = (int)(1e18) + 10;
int n,k,q;
char s[N];
int hh,tt,dq[N];
int arr[N],dp1[N],dp2[N],tmp[N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

inline void solve(){
    fill(dp1,dp1 + n + 5,0);
    fill(dp2,dp2 + n + 5,0);
    n = read(),k = read();
    for (re int i = 1;i <= n;i++) arr[i] = read();
    scanf("%s",s + 1); q = read();
    s[0] = s[n + 1] = '1';
    hh = 1,tt = 0; dq[++tt] = 0;
    for (re int i = 1;i <= n + 1;i++){
        while (hh <= tt && i - dq[hh] > k) hh++;
        dp1[i] = dp1[dq[hh]] + arr[i];
        while (hh <= tt && dp1[dq[tt]] > dp1[i]) tt--;
        if (s[i] == '1') hh = tt = 0; dq[++tt] = i;
    }
    hh = 1,tt = 0; dq[++tt] = n + 1;
    for (re int i = n;~i;i--){
        while (hh <= tt && dq[hh] - i > k) hh++;
        dp2[i] = dp2[dq[hh]] + arr[i];
        while (hh <= tt && dp2[dq[tt]] > dp2[i]) tt--;
        if (s[i] == '1') hh = 1,tt = 0; dq[++tt] = i;
    }
    while (q--){
        int x,v;
        x = read(),v = read();
        int ans = dp1[x] + dp2[x] - 2 * arr[x] + v;
        if (s[x] == '1'){
            printf("%lld\n",ans); continue;
        }
        int r = min(n + 1,x + k);
        int prex = arr[x],pos = x - k + 1; arr[x] = v;
        tmp[x] = dp1[x] - prex + v;
        for (re int i = x - 1;i >= min(0ll,x - k);i--){
            tmp[pos = i] = min(dp1[i],tmp[i + 1]);
            if (s[i] == '1') break;
        }
        for (re int i = x + 1;i <= r;i++){
            chmin(ans,tmp[max(pos,i - k)] + dp2[i]);
            if (s[i] == '1') break;
        }
        printf("%lld\n",ans); arr[x] = prex;
    }
}

signed main(){
    int T; T = read();
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 12132kb

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:

1984533677
1423635430
1597491089
2364998688
1541797430
2223491101
1086915157
1323005204
1323005204
2240907690
1378720602
1323005204
1568135839
2511807344
1323005204
1239870630
1470512859
1483547968
470735446
470735446
211705888
564509290
715543137
470735446
470735446
17
18
18
18
19
19
54
83814688
83...

result:

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