#include "candies.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
long long tree[1000005];
void add(int r, int v){
r++;
for(;r<400005;r+=r&-r)
tree[r]+=v;
}
void add(int l, int r, int v){
add(r,v);
if(l-1>=0)
add(l-1,v);
}
int get(int x){
x++;
int sum=0;
for(;x>=0;x-=x&-x)
sum+=tree[x];
return sum;
}
int get(int r, int val){
return get(r)-get(r-1);
}
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n=c.size(),q=v.size();
vector<int> a(n);
if(n<=2000 && q<=2000){
for(int t=0;t<q;t++){
for(int i=l[t];i<=r[t];i++){
a[i]+=v[t];
a[i]=min(c[i],a[i]);
a[i]=max(a[i],0);
}
}
}
else{
for(int t=0;t<q;t++){
add(l[t],r[t],v[t]);
}
for(int i=0;i<n;i++)
a[i]=max(c[i],get(i,0));
}
return a;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5008 ms |
13004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Execution timed out |
5037 ms |
8020 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
5028 ms |
7628 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
5008 ms |
13004 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |