#include "candies.h"
#include<bits/stdc++.h>
#include <vector>
using namespace std;
#define ll long long
const int MAXN=2e5;
int tree[4*MAXN+1];
int lazy[4*MAXN+1];
vector<int> cc;
vector<int> ans;
void push(int node,int l,int r){
if(lazy[node]){
tree[node]+=lazy[node];
if(l!=r) lazy[node<<1]+=lazy[node],
lazy[node<<1|1]+=lazy[node];
lazy[node]=0;
}
}
void update(int node,int l,int r,int ql,int qr,int v){
push(node,l,r);
if(ql<=l&&r<=qr){
lazy[node]+=v;
push(node,l,r);
return;
}
int mid=(l+r)/2;
if(ql<=mid) update(node<<1,l,mid,ql,qr,v);
if(qr>mid) update(node<<1|1,mid+1,r,ql,qr,v);
tree[node]=max(tree[node<<1],tree[node<<1|1]);
}
void build(int node,int l,int r){
push(node,l,r);
push(node<<1,l,(l+r)/2);
push(node<<1|1,1+(l+r)/2,r);
if(l==r){
ans.push_back(min(tree[node],cc[l]));
return;
}
int mid=(l+r)/2;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
}
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
memset(lazy,0,sizeof lazy);
memset(tree,0,sizeof tree);
for(int i=0;i<4*MAXN;i++) tree[i]=0,lazy[i]=0;
int n = c.size();
int q = v.size();
ans.clear();
cc=c;
for(int j=0;j<q;j++){
int lrr=l[j],rr=r[j],cc=v[j];
update(1,0,n-1,lrr,rr,cc);
}
build(1,0,n-1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
165 ms |
28524 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
6484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |