Submission #969659

#TimeUsernameProblemLanguageResultExecution timeMemory
969659starchanSterilizing Spray (JOI15_sterilizing)C++17
100 / 100
172 ms10576 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define in array<int, 2> #define pb push_back #define pob pop_back #define INF (int)1e17 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) struct segment_tree { vector<int> tree, mx; int K, N; void init(int n) { N = n; tree.resize(4*n+5); mx.resize(4*n+5); return; } void build(const vector<int> &v, int id, int l, int r) { int m = (l+r)/2; if(l == r) { tree[id] = v[m]; mx[id] = v[m]; return; } build(v, 2*id, l, m); build(v, 2*id+1, m+1, r); tree[id] = tree[2*id]+tree[2*id+1]; mx[id] = max(mx[2*id], mx[2*id+1]); return; } void cringe(int ql, int qr, int id, int l, int r) { if(K == 1) return; if(qr < l || r < ql) return; if(l == r) { tree[id]/=K; mx[id]/=K; return; } int m = (l+r)/2; if(mx[2*id]) cringe(ql, qr, 2*id, l, m); if(mx[2*id+1]) cringe(ql, qr, 2*id+1, m+1, r); tree[id] = tree[2*id]+tree[2*id+1]; mx[id] = max(mx[2*id], mx[2*id+1]); return; } void upd(int ql, int qr, int id, int l, int r) { if(qr < l || r < ql) return; if(ql <= l && r <= qr) { if(mx[id]) cringe(ql, qr, id, l, r); return; } int m = (l+r)/2; upd(ql, qr, 2*id, l, m); upd(ql, qr, 2*id+1, m+1, r); tree[id] = tree[2*id]+tree[2*id+1]; mx[id] = max(mx[2*id], mx[2*id+1]); return; } void pnt(int p, int Val, int id, int l, int r) { if(l == r) { tree[id] = Val; mx[id] = Val; return; } int m = (l+r)/2; if(p <= m) pnt(p, Val, 2*id, l, m); else pnt(p, Val, 2*id+1, m+1, r); tree[id] = tree[2*id]+tree[2*id+1]; mx[id] = max(mx[2*id], mx[2*id+1]); return; } int query(int ql, int qr, int id, int l, int r) { if(qr < l || r < ql) return 0; if(ql <= l && r <= qr) return tree[id]; int m = (l+r)/2; int s1 = query(ql, qr, 2*id, l, m); int s2 = query(ql, qr, 2*id+1, m+1, r); return s1+s2; } }; signed main() { fast(); segment_tree work; int n, q; cin >> n >> q >> work.K; vector<int> a(n+1); work.init(n); for(int i = 1; i <= n; i++) cin >> a[i]; work.build(a, 1, 1, n); while(q--) { int typ, x, y; cin >> typ >> x >> y; if(typ == 1) work.pnt(x, y, 1, 1, n); else if(typ == 2) work.upd(x, y, 1, 1, n); else if(typ == 3) cout << work.query(x, y, 1, 1, n) << "\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...