Submission #879011

#TimeUsernameProblemLanguageResultExecution timeMemory
879011hafoSterilizing Spray (JOI15_sterilizing)C++14
100 / 100
129 ms5468 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define pb push_back #define pa pair<int, int> #define pall pair<ll, int> #define fi first #define se second #define TASK "test" #define Size(x) (int) x.size() #define all(x) x.begin(), x.end() using namespace std; template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;} const int MOD = 1e9 + 7; const int LOG = 20; const int maxn = 2e5 + 7; const ll oo = 1e18 + 69; int n, q, k, t, l, r, a[maxn]; struct ST { ll st[4 * maxn]; void build(int id, int l, int r) { if(l == r) { st[id] = a[l]; return; } int mid = l + r >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); st[id] = st[id << 1] + st[id << 1 | 1]; } void update(int id, int l, int r, int pos, int val) { if(pos < l || pos > r) return; if(l == r) { st[id] = val; return; } int mid = l + r >> 1; update(id << 1, l, mid, pos, val); update(id << 1 | 1, mid + 1, r, pos, val); st[id] = st[id << 1] + st[id << 1 | 1]; } void update2(int id, int l, int r, int u, int v) { if(r < u || l > v) return; if(u <= l && r <= v) { if(st[id] == 0) return; if(l == r) { st[id] /= k; return; } } int mid = l + r >> 1; update2(id << 1, l, mid, u, v); update2(id << 1 | 1, mid + 1, r, u, v); st[id] = st[id << 1] + st[id << 1 | 1]; } ll get(int id, int l, int r, int u, int v) { if(r < u || l > v) return 0; if(u <= l && r <= v) return st[id]; int mid = l + r >> 1; return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v); } } st; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen(TASK".inp", "r", stdin); //freopen(TASK".out", "w", stdout); cin>>n>>q>>k; for(int i = 1; i <= n; i++) cin>>a[i]; st.build(1, 1, n); while(q--) { cin>>t>>l>>r; if(t == 1) { st.update(1, 1, n, l, r); } if(t == 2) { if(k > 1) { st.update2(1, 1, n, l, r); } } if(t == 3) { cout<<st.get(1, 1, n, l, r)<<"\n"; } } return 0; }

Compilation message (stderr)

sterilizing.cpp: In member function 'void ST::build(int, int, int)':
sterilizing.cpp:32:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |         int mid = l + r >> 1;
      |                   ~~^~~
sterilizing.cpp: In member function 'void ST::update(int, int, int, int, int)':
sterilizing.cpp:44:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |         int mid = l + r >> 1;
      |                   ~~^~~
sterilizing.cpp: In member function 'void ST::update2(int, int, int, int, int)':
sterilizing.cpp:60:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |         int mid = l + r >> 1;
      |                   ~~^~~
sterilizing.cpp: In member function 'long long int ST::get(int, int, int, int, int)':
sterilizing.cpp:69:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |         int mid = l + r >> 1;
      |                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...