/*
Mayoeba Yabureru
*/
#include<bits/stdc++.h>
using namespace std;
struct Node {
int valuel = 0, valuer = 0, lazyadd = 0, lazyset = -1;
int left = -1, right = -1;
Node() {}
};
Node st[5000006];
int cnt;
void push(int node, int l, int r) {
int left = st[node].left, right = st[node].right;
if (st[node].lazyset != -1) {
//cout << '*' << l << ' ' << r << ' ' << st[node].lazyset << ' ' << st[node].lazyadd << endl;
if (st[node].lazyset == 0) {
st[node].valuel = 0;
st[node].valuer = 0;
}
else {
st[node].valuel = l;
st[node].valuer = r;
}
st[node].valuel += st[node].lazyadd;
st[node].valuer += st[node].lazyadd;
if (l != r) {
st[left].lazyset = st[right].lazyset = st[node].lazyset;
st[left].lazyadd = st[right].lazyadd = 0;
st[left].lazyadd += st[node].lazyadd;
st[right].lazyadd += st[node].lazyadd;
}
st[node].lazyset = -1;
st[node].lazyadd = 0;
}
else if (st[node].lazyadd != 0) {
st[left].lazyadd += st[node].lazyadd;
st[right].lazyadd += st[node].lazyadd;
st[node].valuel += st[node].lazyadd;
st[node].valuer += st[node].lazyadd;
st[node].lazyadd = 0;
}
}
void update(int node, int l, int r, int val) {
if (st[node].left == -1) {
st[node].left = ++ cnt;
st[cnt] = Node();
}
if (st[node].right == -1) {
st[node].right = ++ cnt;
st[cnt] = Node();
}
//cout << ' ' << l << ' ' << r << ' ' << st[node].lazyset << endl;
push(node, l, r);
long long vall = st[node].valuel, valr = st[node].valuer;
//cout << ' ' << l << ' ' << r << ' ' << vall << ' ' << valr << ' ' << val << endl;
if (val >= 0 && vall + val > l && valr + val > r) { // all the boxes with cap inbetween l and r are set to equal the cap
st[node].lazyadd = 0;
st[node].lazyset = 1;
push(node, l, r);
return;
}
if (val >= 0 && vall + val <= l && valr + val <= r) { // all the boxes with cap inbetween l and r are added val
st[node].lazyadd = val;
push(node, l, r);
return;
}
if (val < 0 && vall + val < 0 && valr + val < 0) { // all the boxes with cap inbetween l and r are set to equal the 0
st[node].lazyadd = 0;
st[node].lazyset = 0;
push(node, l, r);
return;
}
if (val < 0 && vall + val >= 0 && valr + val >= 0) { // all the boxes with cap inbetween l and r are added val
st[node].lazyadd = val;
push(node, l, r);
return;
}
int mid = (l + r) / 2;
int left = st[node].left, right = st[node].right;
update(left, l, mid, val);
update(right, mid + 1, r, val);
st[node].valuel = st[left].valuel;
st[node].valuer = st[right].valuer;
}
int query(int node, int l, int r, int x) {
if (st[node].left == -1) {
st[node].left = ++ cnt;
st[cnt] = Node();
}
if (st[node].right == -1) {
st[node].right = ++ cnt;
st[cnt] = Node();
}
push(node, l, r);
if (l == x && r == x) return st[node].valuel;
int mid = (l + r) / 2;
if (x <= mid) return query(st[node].left, l, mid, x);
return query(st[node].right, mid + 1, r, x);
}
vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n = c.size();
st[0] = Node();
for (auto x : v) update(0, 1, 1e9, x);
vector<int> s(n);
for (int i = 0; i < n; i ++) {
//cout << ' ' << c[i] << endl;
s[i] = query(0, 1, 1e9, c[i]);
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
117840 KB |
Output is correct |
2 |
Incorrect |
46 ms |
117580 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
198 ms |
129668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
117840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
117828 KB |
Output is correct |
2 |
Correct |
47 ms |
117688 KB |
Output is correct |
3 |
Correct |
240 ms |
125084 KB |
Output is correct |
4 |
Correct |
145 ms |
121428 KB |
Output is correct |
5 |
Correct |
262 ms |
128340 KB |
Output is correct |
6 |
Correct |
351 ms |
128848 KB |
Output is correct |
7 |
Runtime error |
326 ms |
256084 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
117840 KB |
Output is correct |
2 |
Incorrect |
46 ms |
117580 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |