QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317789#5415. RopewayduckindogWA 3ms10044kbC++142.1kb2024-01-29 18:28:372024-01-29 18:28:38

Judging History

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

  • [2024-01-29 18:28:38]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:10044kb
  • [2024-01-29 18:28:37]
  • 提交

answer

//from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

const int N = 5e5 + 10;
int n, k;
int a[N];
string s;
int f[N], g[N], h[N];
int q;

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }
  int test; cin >> test;
  while (test--) {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    a[n + 1] = f[n + 1] = g[n + 1] = 0;
    cin >> s; s = '@' + s;
    deque<int> dq;
    dq.push_back(0);
    for (int i = 1; i <= n; ++i) {
      while (dq.size() && dq.back() < i - k) dq.pop_back();
      f[i] = f[dq.back()] + a[i];
      while (dq.size() && f[dq.front()] >= f[i]) dq.pop_front();
      if (s[i] == '1') dq.clear();
      dq.push_front(i);
    }
    dq.clear();
    dq.push_back(n + 1);
    for (int i = n; i >= 1; --i) {
      while (dq.size() && dq.back() > i + k) dq.pop_back();
      g[i] = g[dq.back()] + a[i];
      while (dq.size() && g[dq.front()] >= g[i]) dq.pop_front();
      if (s[i] == '1') dq.clear();
      dq.push_front(i);
    }

    cin >> q;
    while (q--) {
      int p, v; cin >> p >> v;
      int pre = a[p]; a[p] = v;
      for (int i = p; i <= min(n, p + k); ++i) h[i] = f[i];
      dq.clear();
      for (int i = max(0, p - k); i < p; ++i) {
        while (dq.size() && f[dq.front()] >= f[i]) dq.pop_front();
        if (s[i] == '1') dq.clear();
        dq.push_front(i);
      }
      for (int i = p; i <= min(n, p + k); ++i) {
        while (dq.size() && dq.back() < i - k) dq.pop_back();
        f[i] = f[dq.back()] + a[i];
        while (dq.size() && f[dq.front()] >= f[i]) dq.pop_front();
        if (s[i] == '1') dq.clear();
        dq.push_front(i);
      }
      int mi = 1e9;
      int it = dq.back();
      for (int i = it + 1; i <= min(n + 1, it + k); ++i) {
        mi = min(mi, g[i]);
        if (s[i] == '1') {
           mi = g[i];
          break;
        }
      }
      cout << f[it] + mi << "\n";
      for (int i = p; i <= min(n, p + k); ++i) f[i] = h[i];
    }


  }

}


详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 10040kb

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

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:

-1822080865
-1995855330
-1498911851
-1915905871
-1877693330
-1939251458
-1512511954
-1512511954
-1773397736
2075053968
-1456796556
-1773397736
-1489871263
-1949013674
-1773397736
-1791776324
-1286648210
-1612854972
470735446
470735446
211705888
564509290
809316981
715543137
564509290
18
18
18
18
19
...

result:

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