# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1233457 | Timosh | Distributing Candies (IOI21_candies) | C++20 | 0 ms | 0 KiB |
#include "bits/stdc++.h"
#include "candies.h"
using namespace std;
struct node
{
int lz;
};
vector<node> t;
vector<int> C;
vector<int> ans;
int n;
void push(int l, int r, int i)
{
if (l != r)
{
t[i * 2].lz += t[i].lz;
t[i * 2 + 1].lz += t[i].lz;
t[i].lz = 0;
}
}
void upd(int l, int r, int x, int tl = 0, int tr = n - 1, int i = 1)
{
push(tl, tr, i);
if (l > tr || tl > r)
return;
if (l <= tl && tr <= r)
{
t[i].lz += x;
push(tl, tr, i);
return;
}
int m = (tl + tr) / 2;
upd(l, r, x, tl, m, i * 2);
upd(l, r, x, m + 1, tr, i * 2 + 1);
}
void get(int tl = 0, int tr = n - 1, int i = 1)
{
int m = (tl + tr) / 2;
push(tl, tr, i);
if (tl == tr)
ans[tl] = t[i].lz;
else
{
get(tl, m, i * 2);
get(m + 1, tr, i * 2 + 1);
}
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
n = c.size();
C = c;
t.resize(4 * n);
ans.resize(n);
for (int i = 0; i < n; i++)
upd(i, i, 0);
for (int i = 0; i < l.size(); i++)
upd(l[i], r[i], v[i]);
get();
for (int i = 0; i < n; i++)
ans[i] = max(min(ans[i], c[i]), 0);
return ans;
}
int main()
{
for (auto &i : distribute_candies({2, 4, 2}, {0, 0}, {2, 2, 1}, {5, -1, 3}))
cout << i << ' ';
return 0;
}