#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> gc;
struct SegmentTree {
vector<int> tree;
vector<int> lazy;
void push(int v, int l, int r) {
if(l==r) {
tree[v] += lazy[v];
tree[v] = max(0, tree[v]);
tree[v] = min(gc[l], tree[v]);
lazy[v] = 0;
} else {
int m = (l+r)/2;
if(lazy[2*v]) push(2*v, l, m);
if(lazy[2*v + 1]) push(2*v + 1, m+1, r);
lazy[2*v] = lazy[v];
lazy[2*v+1] = lazy[v];
lazy[v] = 0;
}
}
void Update(int p, int l, int r, int a, int b, int x) {
if(b < l || a > r) return;
if(l >= a && r <= b) {
if(lazy[p]) push(p, l, r);
lazy[p] = x;
} else {
push(p, l, r);
int m = (l+r)/2;
Update(2*p, l, m, a, b, x);
Update(2*p + 1, m+1, r, a, b, x);
}
}
int Get(int p, int l, int r, int i) {
push(p,l,r);
if(l == r && l == i) return tree[p];
if(r < i || l > i) return 0;
int m = (l+r)/2;
return Get(2*p, l, m, i) + Get(2*p + 1, m+1, r, i);
}
SegmentTree(int n) {
tree.resize(4*n, 0);
lazy.resize(4*n, 0);
}
};
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = c.size();
gc = c;
SegmentTree st(n);
vector<int> s;
for(int i = 0; i < v.size(); i++) {
st.Update(1, 0, n-1, l[i], r[i], v[i]);
}
for(int i = 0; i < n; i++) {
s.push_back(st.Get(1, 0, n-1, i));
}
return s;
}
Compilation message
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5042 ms |
13548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
900 ms |
5092 KB |
Output is correct |
3 |
Correct |
855 ms |
12292 KB |
Output is correct |
4 |
Execution timed out |
5053 ms |
19488 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1935 ms |
5084 KB |
Output is correct |
4 |
Correct |
2736 ms |
10100 KB |
Output is correct |
5 |
Execution timed out |
5038 ms |
13516 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
468 KB |
Output is correct |
6 |
Execution timed out |
5042 ms |
13548 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |