#include <bits/stdc++.h>
using namespace std;
void update(int x, int l, int r, int segmenttree[], int ls, int rs, int vs)
{
if (l>rs || r<ls)
return;
if (l>=ls && r<=rs)
{
segmenttree[x]=segmenttree[x]+vs;
return;
}
if (r-l==1)
return;
int m=(l+r)/2;
update(2*x+1, l, m, segmenttree, ls, rs, vs);
update(2*x+2, m, r, segmenttree, ls, rs, vs);
return;
}
void final(int x, int l, int r, int segmenttree[], vector<int> &s, vector<int> c)
{
if (r>s.size())
return;
for (int i=l; i<r; i++)
s[i]=min(s[i]+segmenttree[x], c[i]);
if (r-l==1)
return;
int m=(l+r)/2;
final(2*x+1, l, m, segmenttree, s, c);
final(2*x+2, m, r, segmenttree, s, c);
return;
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
int n=c.size();
int q=l.size();
if (n<=2000 && q<=2000)
{
vector<int> s(n);
for (int i=0; i<n; i++)
s[i]=0;
for (int i=0; i<q; i++)
{
if (v[i]>0)
for (int j=l[i]; j<=r[i]; j++)
s[j]=min(s[j]+v[i], c[j]);
else
for (int j=l[i]; j<=r[i]; j++)
s[j]=max(s[j]+v[i], 0);
}
return s;
}
int t=0;
for (auto x : v)
if (x>0)
t=t+1;
if (t==q)
{
int m=pow(2, 19);
int segmenttree[m]={0};
for (int i=0; i<q; i++)
update(0, 0, n, segmenttree, l[i], r[i]+1, v[i]);
vector<int> s(n);
for (int i=0; i<n; i++)
s[i]=0;
final(0, 0, n, segmenttree, s, c);
return s;
}
}
Compilation message
candies.cpp: In function 'void final(int, int, int, int*, std::vector<int>&, std::vector<int>)':
candies.cpp:24:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if (r>s.size())
| ~^~~~~~~~~
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:73:1: warning: control reaches end of non-void function [-Wreturn-type]
73 | }
| ^
# |
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 |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5079 ms |
25736 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
97 ms |
10152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
59 ms |
9804 KB |
Output isn't correct |
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 |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Execution timed out |
5079 ms |
25736 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |