Submission #68774169


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int N = 200000 + 5;
ll A[N], B[N], C[N];

struct ST {
  ll t[4*N];

  void build(int n, int b, int e) {
    if(b == e) {
      t[n] = C[b];
      return;
    }
    int m = (b + e) >> 1;
    int l = (n << 1) + 1, r = (n << 1) + 2;
    build(l, b, m);
    build(r, m+1, e);
    t[n] = t[l] + t[r];
  }

  void upd(int n, int b, int e, int i, ll x) {
    if(b > i || e < i) return;
    if(b == e) {
      t[n] = x;
      return;
    }
    int m = (b + e) >> 1;
    int l = (n << 1) + 1, r = (n << 1) + 2;
    upd(l, b, m, i, x);
    upd(r, m+1, e, i, x);
    t[n] = t[l] + t[r];
  }

  ll query(int n, int b, int e, int i, int j) {
    if(b > j || e < i) return 0;
    if(i <= b && e <= j) return t[n];
    int m = (b + e) >> 1;
    int l = (n << 1) + 1, r = (n << 1) + 2;
    return query(l, b, m, i, j) + query(r, m+1, e, i, j);
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, q;
  cin >> n >> q;
  for(int i = 0; i < n; i++) cin >> A[i];
  for(int i = 0; i < n; i++) cin >> B[i];

  for(int i = 0; i < n; i++) C[i] = min(A[i], B[i]);

  ST seg;
  seg.build(0, 0, n-1);

  while(q--) {
    char c;
    int l;
    ll r;
    cin >> c >> l >> r;
    l--;

    if(c == 'A') A[l] = r;
    else B[l] = r;

    C[l] = min(A[l], B[l]);
    seg.upd(0, 0, n-1, l, C[l]);

    cout << seg.query(0, 0, n-1, 0, n-1) << "\n";
  }

  return 0;
}

Submission Info

Submission Time
Task C - Sum of Min Query
User JyuK_SIR
Language C++ 20 (gcc 12.2)
Score 300
Code Size 1516 Byte
Status AC
Exec Time 144 ms
Memory 14552 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 23
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 4 ms 9708 KiB
00_sample_01.txt AC 3 ms 9708 KiB
00_sample_02.txt AC 4 ms 9716 KiB
01_random_00.txt AC 4 ms 9644 KiB
01_random_01.txt AC 135 ms 14552 KiB
01_random_02.txt AC 131 ms 14376 KiB
01_random_03.txt AC 56 ms 12040 KiB
01_random_04.txt AC 134 ms 13920 KiB
01_random_05.txt AC 50 ms 12684 KiB
01_random_06.txt AC 109 ms 11940 KiB
01_random_07.txt AC 25 ms 11952 KiB
01_random_08.txt AC 133 ms 14412 KiB
01_random_09.txt AC 133 ms 14356 KiB
01_random_10.txt AC 133 ms 14540 KiB
01_random_11.txt AC 119 ms 14376 KiB
01_random_12.txt AC 139 ms 14452 KiB
01_random_13.txt AC 139 ms 14328 KiB
01_random_14.txt AC 134 ms 14388 KiB
01_random_15.txt AC 133 ms 14540 KiB
01_random_16.txt AC 144 ms 14400 KiB
01_random_17.txt AC 140 ms 14432 KiB
01_random_18.txt AC 135 ms 14028 KiB
01_random_19.txt AC 139 ms 14540 KiB