Submission #526852

# Submission time Handle Problem Language Result Execution time Memory
526852 2022-02-16T10:25:34 Z arnav2004 Sterilizing Spray (JOI15_sterilizing) C++17
100 / 100
252 ms 8204 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX = 1e5 + 5;
int N,M,K,A[MX];
pair<int,int> seg[4 * MX];
pair<int,int> calculate(const pair<int,int> &x, const pair<int,int> &y){
  return {x.first + y.first, max(x.second, y.second)};
}
void build(int idx, int low, int high){
  if(low == high){
    seg[idx] = {A[low], A[low]};
    return;
  }
  int mid = (low + high) >> 1;
  build(idx * 2 + 1, low, mid);
  build(idx * 2 + 2, mid + 1, high);
  seg[idx] = calculate(seg[idx * 2 + 1], seg[idx * 2 + 2]);
}
int query(int idx, int low, int high, int L, int R){
  if(L <= low && high <= R)
    return seg[idx].first;
  if(low > R || high < L)
    return 0;
  int mid = (low + high) >> 1;
  return query(idx * 2 + 1, low, mid, L, R) + query(idx * 2 + 2, mid + 1, high, L, R);
}
int get_max(int idx, int low, int high, int L, int R){
  if(L <= low && high <= R)
    return seg[idx].second;
  if(low > R || high < L)
    return 0;
  int mid = (low + high) >> 1;
  return max(get_max(idx * 2 + 1, low, mid, L, R), get_max(idx * 2 + 2, mid + 1, high, L, R));
}
void update(int idx, int low, int high, int L, int R, int v){
  if(L <= low && high <= R){
    seg[idx] = {v, v};
    return;
  }
  if(low > R || high < L)
    return;
  int mid = (low + high) >> 1;
  update(idx * 2 + 1, low, mid, L, R, v);
  update(idx * 2 + 2, mid + 1, high, L, R, v);
  seg[idx] = calculate(seg[idx * 2 + 1], seg[idx * 2 + 2]);
}
void update2(int idx, int low, int high, int L, int R){
  if(low > R || high < L) return;
  if(seg[idx].second == 0) return;
  if(low == high){
    A[low] /= K;
    seg[idx] = {A[low], A[low]};
    return;
  }
  int mid = (low + high) >> 1;
  update2(idx * 2 + 1, low, mid, L, R);
  update2(idx * 2 + 2, mid + 1, high, L, R);
  seg[idx] = calculate(seg[idx * 2 + 1], seg[idx * 2 + 2]);
}
signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> K;
  for(int i = 0; i < N; i++)
    cin >> A[i];
  build(0, 0, N - 1);
  while(M--){
    int T; cin >> T;
    if(T == 3){
      int L,R; cin >> L >> R;
      L--; R--;
      cout << query(0, 0, N - 1, L, R) << '\n';
    }
    else if(T == 2){
      int L,R; cin >> L >> R;
      L--; R--;
      if(K == 1) continue;
      update2(0, 0, N - 1, L, R);
    }
    else{
      int k,x; cin >> k >> x;
      k--;
      A[k] = x;
      update(0, 0, N - 1, k, k, x);
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 4 ms 452 KB Output is correct
6 Correct 5 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 460 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 5092 KB Output is correct
2 Correct 41 ms 4568 KB Output is correct
3 Correct 39 ms 7088 KB Output is correct
4 Correct 61 ms 7576 KB Output is correct
5 Correct 77 ms 8204 KB Output is correct
6 Correct 61 ms 8044 KB Output is correct
7 Correct 59 ms 8116 KB Output is correct
8 Correct 61 ms 8108 KB Output is correct
9 Correct 74 ms 7908 KB Output is correct
10 Correct 57 ms 7872 KB Output is correct
11 Correct 54 ms 7936 KB Output is correct
12 Correct 67 ms 7968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1016 KB Output is correct
2 Correct 13 ms 2996 KB Output is correct
3 Correct 16 ms 3120 KB Output is correct
4 Correct 59 ms 2692 KB Output is correct
5 Correct 55 ms 6636 KB Output is correct
6 Correct 53 ms 6600 KB Output is correct
7 Correct 60 ms 6768 KB Output is correct
8 Correct 71 ms 6620 KB Output is correct
9 Correct 48 ms 6476 KB Output is correct
10 Correct 50 ms 6472 KB Output is correct
11 Correct 53 ms 6468 KB Output is correct
12 Correct 83 ms 6464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 4476 KB Output is correct
2 Correct 90 ms 4620 KB Output is correct
3 Correct 123 ms 3964 KB Output is correct
4 Correct 111 ms 3504 KB Output is correct
5 Correct 125 ms 7872 KB Output is correct
6 Correct 152 ms 7864 KB Output is correct
7 Correct 135 ms 7864 KB Output is correct
8 Correct 178 ms 7944 KB Output is correct
9 Correct 156 ms 7816 KB Output is correct
10 Correct 221 ms 7748 KB Output is correct
11 Correct 132 ms 7740 KB Output is correct
12 Correct 252 ms 7776 KB Output is correct