Submission #1279335

#TimeUsernameProblemLanguageResultExecution timeMemory
1279335Bui_Quoc_CuongSterilizing Spray (JOI15_sterilizing)C++20
100 / 100
132 ms5384 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, q; int a[N]; pair <long long, int> st[4 * N]; void update (int id, int l, int r, int u, int v, int k) { if (l > v || r < u || st[id].second == 0) return; if (l == r) { st[id].first /= k; st[id].second /= k; return; } int mid = (l + r) >> 1; update (id << 1, l, mid, u, v, k); update (id << 1 | 1, mid + 1, r, u, v, k); st[id].first = st[id << 1].first + st[id << 1 | 1].first; st[id].second = max(st[id << 1].second, st[id << 1 | 1].second); } long long get(int id, int l, int r, int u, int v) { if (l > v || r < u) return 0; if (l >= u && r <= v) return st[id].first; int mid = (l + r) >> 1; return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v); } void build (int id, int l, int r) { if (l == r) { st[id].first = st[id].second = a[l]; return; } int mid = (l + r) >> 1; build (id << 1, l, mid); build (id << 1 | 1, mid + 1, r); st[id].first = st[id << 1].first + st[id << 1 | 1].first; st[id].second = max(st[id << 1].second, st[id << 1 | 1].second); } void up (int pos, int val) { int id = 1, l = 1, r = n; while (l < r) { int mid = (l + r) >> 1; if (pos <= mid) id = id << 1, r = mid; else id = id << 1 | 1, l = mid + 1; } st[id].first = st[id].second = val; while (id > 1) { id >>= 1; st[id].first = st[id << 1].first + st[id << 1 | 1].first; st[id].second = max(st[id << 1].second, st[id << 1 | 1].second); } } void solve () { int k; cin >> n >> q >> k; for (int i = 1; i <= n; i++) cin >> a[i]; build(1, 1, n); while (q--) { int sign; cin >> sign; if (sign == 1) { int id, val; cin >> id >> val; up (id, val); } else if (sign == 2) { int l, r; cin >> l >> r; if (k == 1) continue; update (1, 1, n, l, r, k); } else { int l, r; cin >> l >> r; cout << get(1, 1, n, l, r) << "\n"; } } } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); #define kieuoanh "JOI15_sterilizing" if (fopen(kieuoanh".inp", "r")) { freopen(kieuoanh".inp", "r", stdin); freopen(kieuoanh".out", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(kieuoanh".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(kieuoanh".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...