#include <bits/stdc++.h>
using namespace std;
const int N= 2e5+5;
vector <int> c;
int t[N*4];
int lazy[N*4];
vector <int> s;
void applay(int node, int l, int r, int val) {
lazy[node] = val;
if (l == r && val != 0) {
if (val > 0) {
t[node] = min(t[node]+val,c[l]);
} else {
t[node] = max(t[node]+val,0);
}
}
}
void push(int node, int l, int r) {
if (lazy[node] != 0) {
int mid = (l+r)/2;
applay(node*2,l,mid,lazy[node]);
applay(node*2+1,mid+1,r,lazy[node]);
lazy[node] = 0;
}
}
void update(int node, int l, int r, int L, int R, int val) {
if (r < L || l > R) return;
push(node,l,r);
if (l >= L && r <= R) {
applay(node,l,r,val);
return;
}
int mid = (l+r)/2;
update(node*2,l,mid,L,R,val);
update(node*2+1,mid+1,r,L,R,val);
}
void getans(int node, int l, int r) {
if (l == r) {
s[l] = t[node];
return;
}
push(node,l,r);
int mid = (l+r)/2;
getans(node*2,l,mid);
getans(node*2+1,mid+1,r);
}
std::vector<int> distribute_candies(std::vector<int> x, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
c = x;
int n = x.size();
int q = l.size();
for (int i = 0; i < q; i++) {
update(1,0,n-1,l[i],r[i],v[i]);
}
s.assign(n,0);
getans(1,0,n-1);
return s;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |