Submission #446440

#TimeUsernameProblemLanguageResultExecution timeMemory
446440luciocfDistributing Candies (IOI21_candies)C++17
11 / 100
137 ms9264 KiB
#include <bits/stdc++.h> #include "candies.h" using namespace std; typedef long long ll; const int maxn = 2e5+10; struct FenwickTree { ll bit[maxn]; void upd(int x, ll v) { for (; x < maxn; x += (x&-x)) bit[x] += v; } ll soma(int x) { ll ans = 0; for (; x > 0; x -= (x&-x)) ans += bit[x]; return ans; } ll get(int l, int r) { return soma(r)-soma(l-1); } } BIT; ll value(ll v, ll add, int C) { if (add + v > 1ll*C) return C; if (add + v < 0) return 0; return add+v; } int a[maxn]; vector<int> distribute_candies(vector<int> c, vector<int> L, vector<int> R, vector<int> V) { int n = c.size(), q = L.size(); if (max(n, q) <= 2000) { for (int i = 0; i < q; i++) { for (int j = L[i]; j <= R[i]; j++) a[j] = value(a[j], V[i], c[j]); } vector<int> ans; for (int i = 0; i < n; i++) ans.push_back(a[i]); return ans; } for (int i = 0; i < q; i++) { BIT.upd(L[i]+1, 1ll*V[i]); BIT.upd(R[i]+2, -1ll*V[i]); } vector<int> ans; for (int i = 1; i <= n; i++) { if (BIT.soma(i) >= c[i-1]) ans.push_back(c[i-1]); else ans.push_back(BIT.soma(i)); } return ans; }
#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...