제출 #970758

#제출 시각아이디문제언어결과실행 시간메모리
970758Beerus13Sterilizing Spray (JOI15_sterilizing)C++14
100 / 100
206 ms7564 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 5; struct node { ll sum, mx; node() {} node(ll sum, ll mx) : sum(sum), mx(mx) {} }; node operator + (node &a, node &b) { node res; res.sum = a.sum + b.sum; res.mx = max(a.mx, b.mx); return res; } int n, q, k; node st[N << 2]; void update_point(int u, int val) { int id = 1, l = 1, r = n; while(l < r) { int m = l + r >> 1; if(u > m) id = id << 1 | 1, l = m + 1; else id = id << 1, r = m; } st[id] = node(val, val); while(id > 1) id = id >> 1, st[id] = st[id << 1] + st[id << 1 | 1]; } void update(int u, int v, int id = 1, int l = 1, int r = n) { if(u > r || v < l || st[id].mx == 0 || k == 1) return; if(l == r) { st[id].sum /= k; st[id].mx /= k; return; } int m = l + r >> 1; update(u, v, id << 1, l, m); update(u, v, id << 1 | 1, m + 1, r); st[id] = st[id << 1] + st[id << 1 | 1]; } ll query(int u, int v, int id = 1, int l = 1, int r = n) { if(u > r || v < l) return 0; if(u <= l && r <= v) return st[id].sum; int m = l + r >> 1; return query(u, v, id << 1, l, m) + query(u, v, id << 1 | 1, m + 1, r); } void solve() { cin >> n >> q >> k; for(int i = 1, x; i <= n; ++i) { cin >> x; update_point(i, x); } while(q--) { int type, u, v; cin >> type >> u >> v; if(type == 1) update_point(u, v); if(type == 2) update(u, v); if(type == 3) cout << query(u, v) << '\n'; } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int test = 1; // cin >> test; while(test--) solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

sterilizing.cpp: In function 'void update_point(int, int)':
sterilizing.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         int m = l + r >> 1;
      |                 ~~^~~
sterilizing.cpp: In function 'void update(int, int, int, int, int)':
sterilizing.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     int m = l + r >> 1;
      |             ~~^~~
sterilizing.cpp: In function 'long long int query(int, int, int, int, int)':
sterilizing.cpp:49:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     int m = 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...