#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
int seg[800005], mx[800005], mn[800005];
vector<int> vec[200005], ans;
void update(int i, int l, int r, int x, int y)
{
if (l==r)
{
seg[i]=mx[i]=mn[i]=y;
return;
}
int mid=(l+r)/2;
if (x<=mid)
update(i*2, l, mid, x, y);
else
update(i*2+1, mid+1, r, x, y);
seg[i]=seg[i*2]+seg[i*2+1];
mx[i]=max(mx[i*2], mx[i*2+1]);
mn[i]=min(mn[i*2], mn[i*2+1]);
}
int query(int i, int l, int r, int x)
{
if (l==r)
return max(0, min(x, seg[i]));
int mid=(l+r)/2, res;
if (mx[i*2+1]-mn[i*2+1]>=x)
return query(i*2+1, mid+1, r, x);
res=query(i*2, l, mid, x);
if (res+mx[i*2+1]>=x)
return x-(mx[i*2+1]-seg[i*2+1]);
if (res+mn[i*2+1]<=0)
return seg[i*2+1]-mn[i*2+1];
return res+seg[i*2+1];
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
int n=c.size(), q=v.size();
for (int i=0; i<q; i++)
{
vec[l[i]].push_back(i);
vec[r[i]+1].push_back(i);
}
for (int i=0; i<n; i++)
{
for (int j:vec[i])
{
if (l[j]==i)
update(1, 0, q-1, j, v[j]);
else
update(1, 0, q-1, j, 0);
}
ans.push_back(query(1, 0, q-1, c[i]));
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
323 ms |
29632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |