Submission #1126650

#TimeUsernameProblemLanguageResultExecution timeMemory
1126650Zero_OPSterilizing Spray (JOI15_sterilizing)C++20
100 / 100
167 ms4424 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; int N, K, Q, mx[MAX << 2], a[MAX]; long long st[MAX << 2]; void pull(int id){ st[id] = st[id << 1] + st[id << 1 | 1]; mx[id] = max(mx[id << 1], mx[id << 1 | 1]); } void update(int id, int l, int r, int u, int v){ if(v < l || u > r || mx[id] == 0) return; if(l == r){ mx[id] /= K; st[id] = mx[id]; } else{ int mid = l + r >> 1; update(id << 1, l, mid, u, v); update(id << 1 | 1, mid + 1, r, u, v); pull(id); } } void build(int id, int l, int r){ if(l == r) { mx[id] = a[l], st[id] = a[l]; } else{ int mid = l + r >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); pull(id); } } void update_pos(int id, int l, int r, int pos, int val){ if(l == r){ st[id] = val; mx[id] = val; } else{ int mid = l + r >> 1; if(pos <= mid) update_pos(id << 1, l, mid, pos, val); else update_pos(id << 1 | 1, mid + 1, r, pos, val); pull(id); } } long long query(int id, int l, int r, int u, int v){ if(v < l || u > r) return 0; if(u <= l && r <= v) return st[id]; int mid = l + r >> 1; return query(id << 1, l, mid, u, v) + query(id << 1 | 1, mid + 1, r, u, v); } void debug(int id, int l, int r){ if(l == r) cout << st[id] << " \n"[l == N]; else{ int mid = l + r >> 1; debug(id << 1, l, mid); debug(id << 1 | 1, mid + 1, r); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); #endif // LOCAL cin >> N >> Q >> K; for(int i = 1; i <= N; ++i){ cin >> a[i]; } build(1, 1, N); while(Q--){ int type; cin >> type; if(type == 1){ int a, b; cin >> a >> b; update_pos(1, 1, N, a, b); } else if(type == 2){ int l, r; cin >> l >> r; if(K > 1) update(1, 1, N, l, r); } else{ int l, r; cin >> l >> r; cout << query(1, 1, N, l, r) << '\n'; } // debug(1, 1, N); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...