Submission #400195

#TimeUsernameProblemLanguageResultExecution timeMemory
400195SavicSSterilizing Spray (JOI15_sterilizing)C++14
100 / 100
179 ms8900 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; const int maxn = 100005; const int inf = 1e9 + 5; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) int n, q, K; int niz[maxn]; ll dud[maxn]; void upd(int x, ll val){ while(x <= maxn){ dud[x] += val; x += x&(-x); } } ll query(int x){ ll sum = 0; while(x > 0){ sum += dud[x]; x -= x&(-x); } return sum; } void add(int pos, ll val){ upd(pos, val - niz[pos]); niz[pos] = val; } int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n >> q >> K; ff(i,1,n)cin >> niz[i]; set<int> s; ff(i,1,n)upd(i, niz[i]), s.insert(i); while(q--){ int t; cin >> t; if(t == 1){ int pos, val; cin >> pos >> val; add(pos, val); s.insert(pos); } if(t == 2){ int l, r; cin >> l >> r; if(K == 1)continue; auto A = s.lower_bound(l); auto B = s.upper_bound(r); while(A != B){ add(*A, niz[*A] / K); if(niz[*A] == 0)s.erase(A++); else A++; } } if(t == 3){ int l, r; cin >> l >> r; cout << query(r) - query(l - 1) << '\n'; } } return 0; } /** 5 10 3 1 2 8 1 3 1 2 5 2 3 5 3 2 5 2 1 4 1 3 2 3 3 5 1 2 4 2 1 2 1 1 4 3 1 5 // probati bojenje sahovski ili slicno **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...