#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, q;
int m;
vector<ll> st;
void push(int ind){
st[ind*2] += st[ind];
st[ind*2+1] += st[ind];
st[ind] = 0;
}
void update(int l, int r, int d, int cl = 0, int cr = m-1, int ind = 1){
if(l <= cl && cr <= r){
st[ind] += d;
return;
}
if(r < cl || cr < l)return;
push(ind);
int md = (cl+cr)/2;
update(l, r, d, cl, md, ind*2);
update(l, r, d, md+1, cr, ind*2+1);
}
void pushall(int ind = 1){
if(ind < m){
push(ind);
pushall(ind*2);
pushall(ind*2+1);
}
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
n = c.size(), q = l.size();
m = (1<<int(ceil(log2(n))));
st.assign(m*2, 0);
for(int i = 0; i < q; i++){
update(l[i], r[i], v[i]);
}
pushall();
vector<int> s(n);
for(int i = 0; i < n; i++){
s[i] = min((ll)c[i], st[i+m]);
}
return s;
}
// int main() {
// int n;
// assert(1 == scanf("%d", &n));
// std::vector<int> c(n);
// for(int i = 0; i < n; ++i) {
// assert(scanf("%d", &c[i]) == 1);
// }
// int q;
// assert(1 == scanf("%d", &q));
// std::vector<int> l(q), r(q), v(q);
// for(int i = 0; i < q; ++i) {
// assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
// }
// std::vector<int> ans = distribute_candies(c, l, r, v);
// for(int i = 0; i < n; ++i) {
// if (i > 0) {
// printf(" ");
// }
// printf("%d", ans[i]);
// }
// printf("\n");
// fclose(stdout);
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
11364 KB |
Output is correct |
2 |
Correct |
148 ms |
15524 KB |
Output is correct |
3 |
Correct |
167 ms |
15396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |