Submission #548412

#TimeUsernameProblemLanguageResultExecution timeMemory
548412topovikDistributing Candies (IOI21_candies)C++17
3 / 100
378 ms37256 KiB
#include <bits/stdc++.h> #include "candies.h" #define pb push_back #define f first #define s second using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const ll oo = 1e9 + 7; const ll N = 1e6; const ll M = 21; const ll M1 = 1e6; int a[N]; struct tree { tree *L = NULL; tree *R = NULL; ll l, r; ll sum = 0; ll mdl; tree(ll _l, ll _r) : l(_l), r(_r) { mdl = (l + r) >> 1; if (l == r) return; L = new tree(l, mdl); R = new tree(mdl + 1, r); } void upd(ll _l, ll _r, ll vl) { if (_l > _r) return; if (_l == l && _r == r) { sum += vl; return; } L -> upd(_l, min(mdl, _r), vl); R -> upd(max(mdl + 1, _l), _r, vl); } ll val(ll x) { if (l == r) return sum; L -> sum += sum; R -> sum += sum; sum = 0; if (mdl < x) return R -> val(x); else return L -> val(x); } }; std::vector<int> distribute_candies (std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) { int n = c.size(); int q = l.size(); if (n <= 2000 && q <= 2000) { for (int i = 0; i < q; i++) { for (int j = l[i]; j <= r[i]; j++) a[j] += v[i]; for (int j = 0; j < n; j++) { if (a[j] < 0) a[j] = 0; if (a[j] > c[j]) a[j] = c[j]; } } vector <int> ans(n); for (int i = 0; i < n; i++) ans[i] = a[i]; return ans; } else { tree *root = new tree(0, n - 1); for (int i = 0; i < q; i++) root -> upd(l[i], r[i], v[i]);\ vector <int> ans(n); for (int i = 0; i < n; i++) ans[i] = min((ll)v[i], root -> val(i)); return ans; } } //int main() //{ // ios_base::sync_with_stdio(0); // iostream::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // int n; // cin >> n; // vector <int> c(n); // for (int i = 0; i < n; i++) cin >> c[i]; // int q; // cin >> q; // vector <int> l(q), r(q), v(q); // for (int i = 0; i < q; i++) cin >> l[i] >> r[i] >> v[i]; // vector <int> ans = distribute_candies(c, l, r, v); // for (int i = 0; i < n; i++) cout << ans[i] << " "; //} /* 5 3 2 1 1 2 2 3 2 3 3 4 4 5 4 1 1 2 2 3 3 4 4 5 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...