// #include "candies.h"
#include<bits/stdc++.h>
#include <vector>
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
const int MAXN=2e5;
long long tree[4*MAXN+1][2];
long long lazy[4*MAXN+1];
vector<int> ans;
void push(int node,int l,int r){
if(lazy[node]!=0){
tree[node][0]+=lazy[node];
tree[node][1]+=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 x){
int mid=(l+r)/2;
push(node,l,r);
if(l!=r){
push(node<<1,l,mid);
push(node<<1|1,mid+1,r);
}
if(ql<=l&&r<=qr) {
lazy[node]+=x;
push(node,l,r);
return;
}
if(ql<=mid) update(node<<1,l,mid,ql,qr,x);
if(qr>mid) update(node<<1|1,mid+1,r,ql,qr,x);
tree[node][0]=min(tree[node<<1][0],tree[node<<1|1][0]);
tree[node][1]=max(tree[node<<1][1],tree[node<<1|1][1]);
}
void set_zero(int node,int l,int r){
push(node,l,r);
if(tree[node][1]<0){
update(node,l,r,l,r,-tree[node][1]);
}
if(tree[node][0]>=0) return;
set_zero(node<<1,l,(l+r)/2);
set_zero(node<<1|1,(l+r)/2+1,r);
}
void res(int node,int l,int r,ll x){
push(node,l,r);
int mid=(l+r)/2;
if(tree[node][0]>x){
update(node,l,r,l,r,x-tree[node][0]);
}
if(tree[node][1]<=x) return;
res(node<<1,l,mid,x);
res(node<<1|1,mid+1,r,x);
}
ll query(int node,int l,int r,int ql){
push(node,l,r);
int mid=(l+r)/2;
if(l!=r){
push(node<<1,l,mid);
push(node<<1|1,mid+1,r);
}
if(l==r) return tree[node][1];
if(ql<=mid) return query(node<<1,l,mid,ql);
else return query(node<<1|1,mid+1,r,ql);
}
vector<int> distribute_candies(vector<int> c, vector<int> ql,
vector<int> qr, vector<int> v) {
int n=c.size();
int q=v.size();
memset(tree,0,sizeof(tree));
memset(lazy,0,sizeof(lazy));
vector<int> ans(n,0);
for(int i=0;i<q;i++){
update(1,0,n-1,ql[i],qr[i],v[i]);
if(v[i]<0) set_zero(1,0,n-1);
else res(1,0,n-1,c[0]);
}
for(int i=0;i<n;i++){
int x;
x=query(1,0,n-1,i);
ans[i]=(int)min((ll)c[0],(ll)x);
}
return ans;
}
#ifdef IOI
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;}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
19028 KB |
Output is correct |
2 |
Incorrect |
7 ms |
19028 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5045 ms |
26100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
19028 KB |
Output is correct |
2 |
Correct |
157 ms |
23816 KB |
Output is correct |
3 |
Correct |
78 ms |
22500 KB |
Output is correct |
4 |
Correct |
2907 ms |
26148 KB |
Output is correct |
5 |
Execution timed out |
5073 ms |
26056 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
19028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
19028 KB |
Output is correct |
2 |
Incorrect |
7 ms |
19028 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |