#include <bits/stdc++.h>
using namespace std;
const int N= 2e5+5;
vector <int> c;
long long t[N*4];
int lazy[N*4];
vector <int> s;
void applay(int node, int l, int r, int val) {
if (l == r && val != 0) {
if (val > 0) {
t[node] = min(t[node]+val,(long long)(c[l]));
} else {
t[node] = max(t[node]+val,0LL);
}
} else {
lazy[node] = val;
}
}
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);
}
int getans(int node, int l, int r, int pos) {
if (pos > r || pos < l) return 0;
if (l == r) {
return t[node];
}
push(node,l,r);
int mid = (l+r)/2;
return (getans(node*2,l,mid,pos)+getans(node*2+1,mid+1,r,pos));
}
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]);
}
vector <int> s(n);
for (int i = 0; i < n; i++) {
s[i] = getans(1,0,n-1,i);
}
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... |