제출 #920155

#제출 시각아이디문제언어결과실행 시간메모리
920155BzslayedSterilizing Spray (JOI15_sterilizing)C++17
15 / 100
5037 ms12792 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define coutpair(p) cout << p.first << " " << p.second << "\n" typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; struct node{ int s, e, m; //range is [s,e], m is the middle point ll val; //sum of [s,e] node *l, *r; //create two children l and r, where l is [s,m] and [m+1,e] node (int S, int E){ //constructor called node s = S, e = E, m = (s+e)/2; val = 0; //initially all values are 0 if (s != e){ //node is not yet a leaf, so create two children l = new node(s, m); //create left child r = new node(m+1, e); //create right child } } void spray(int S, int E, ll V){ //increment [S,E] by V if (V == 0 || V == 1) return; if (s == e){ val /= V; return; } if (E <= m) l->spray(S, E, V); //[S,E] is in the left child else if (S > m) r->spray(S, E, V); //[S,E] is in the right child else l->spray(S, m, V), r->spray(m+1, E, V); val = l->val + r->val; //update the range sum } void adjust(int X, ll V){ if (s == e){ val = V; return; } else{ if (X <= m) l->adjust(X, V); else r->adjust(X, V); } val = l->val + r->val; //update the range sum } ll sum(int S, int E){ if (s == S && e == E) return val; //case 1 if (E <= m) return l->sum(S, E); //case 2, recurse to left child else if (S >= m+1) return r->sum(S, E); //case 3, recurse to right child else return l->sum(S, m) + r->sum(m+1, E); //case 4, split the query range, recurse to both childs } } *root; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, q, k, c, s, t, u; cin >> n >> q >> k; root = new node(1, n); for (int i=1; i<=n; i++){ cin >> c; root->adjust(i, c); } for (int i=0; i<q; i++){ cin >> s >> t >> u; if (s == 1){ root->adjust(t, u); } else if (s == 2){ root->spray(t, u, k); } else cout << root->sum(t, u) << "\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...