#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
const int N = 200005;
int n, q, C;
struct ban
{
int ans, l, r;
ban(){}
ban(int ans, int l, int r)
{
this->ans = ans;
this->l = l;
this->r = r;
}
};
ban mer(const ban& l, const ban& r)
{
ban res;
if (l.ans <= r.l)
res.ans = r.ans;
else if (l.ans >= r.r)
res.ans = r.ans + r.r - r.l;
else
res.ans = r.ans + l.ans - r.l;
res.l = l.l + max(0, r.l - l.ans);
res.r = l.r - max(0, l.ans + l.r - l.l - r.r);
if (res.l > res.r)
res.l = res.r = 0;
return res;
}
ban t[N * 4];
void bil(int tl, int tr, int pos)
{
t[pos] = ban(0, 0, C);
if (tl == tr)
return;
int m = (tl + tr) / 2;
bil(tl, m, pos * 2);
bil(m + 1, tr, pos * 2 + 1);
}
void ubd(int tl, int tr, int x, int y, int pos)
{
if (tl == tr)
{
y = min(y, C);
y = max(y, -C);
if (y == 0)
t[pos] = ban(0, 0, C);
else if (y > 0)
t[pos] = ban(y, 0, C - y);
else
t[pos] = ban(0, -y, C);
return;
}
int m = (tl + tr) / 2;
if (x <= m)
ubd(tl, m, x, y, pos * 2);
else
ubd(m + 1, tr, x, y, pos * 2 + 1);
t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}
vector<int> v[N];
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> vv) {
n = sz(c);
q = sz(l);
for (int i = 0; i < q; ++i)
{
v[l[i]].push_back((i + 1));
v[r[i] + 1].push_back(-(i + 1));
}
C = c[0];
bil(0, q - 1, 1);
vector<int> ans(n);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < sz(v[i]); ++j)
{
if (v[i][j] > 0)
{
--v[i][j];
ubd(0, q - 1, v[i][j], vv[v[i][j]], 1);
}
else
{
v[i][j] *= -1;
--v[i][j];
ubd(0, q - 1, v[i][j], 0, 1);
}
}
ans[i] = t[1].ans;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5008 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4928 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
284 ms |
28644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
183 ms |
21152 KB |
Output is correct |
3 |
Correct |
44 ms |
10872 KB |
Output is correct |
4 |
Correct |
278 ms |
29716 KB |
Output is correct |
5 |
Correct |
285 ms |
30104 KB |
Output is correct |
6 |
Correct |
307 ms |
30508 KB |
Output is correct |
7 |
Correct |
300 ms |
29924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5008 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4928 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |