#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>>st;
int l,r;
int lim;
int query(int i, int j, int p) {
if(i > l || j < l)
assert(0);
if(i == j) {
int ans = 0;
for(auto z : st[p]) {
if(z > 0) {
ans += min(z, lim - ans);
} else ans -= min(-z, ans);
}
return ans;
}
int mid = (i+j)/2;
int ans = (i <= l && mid >= l ? query(i,mid,2*p) : query(mid+1,j,2*p+1));
for(auto z : st[p]) {
if(z > 0) {
ans += min(z, lim - ans);
} else ans -= min(-z, ans);
}
return ans;
}
int val;
void update(int i, int j, int p) {
if(i > r || j < l)
return;
if(i >= l && j <= r) {
int app = val;
while(!st[p].empty()) {
if((st[p].back() >= 0 && val >= 0) || st[p].back() <= 0 && val <= 0)
app += st[p].back(),st[p].pop_back();
else break;
}
st[p].push_back(app);
return;
}
for(auto z : st[p])
st[2*p].push_back(z),st[2*p+1].push_back(z);
st[p].clear();
int mid = (i+j)/2;
update(i,mid,2*p),update(mid+1,j,2*p+1);
}
vector<int> distribute_candies(vector<int> c, vector<int> le, vector<int> ri, vector<int> v) {
const int n = (int)c.size();
const int q = (int)v.size();
st.resize(8*n);
for(int i = 0 ; i < q ; i++) {
val = v[i];
l = le[i], r = ri[i];
update(0, n-1, 1);
}
vector<int>ans;
for(int i = 0 ; i < n ; i++) {
lim = c[i];
l = i;
ans.push_back(query(0,n-1,1));
}
return ans;
}
Compilation message
candies.cpp: In function 'void update(int, int, int)':
candies.cpp:40:69: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
40 | if((st[p].back() >= 0 && val >= 0) || st[p].back() <= 0 && val <= 0)
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
12 ms |
6316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2142 ms |
514604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
1198 ms |
423244 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
358 ms |
5968 KB |
Output is correct |
4 |
Correct |
371 ms |
40624 KB |
Output is correct |
5 |
Execution timed out |
5042 ms |
44992 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
12 ms |
6316 KB |
Output is correct |
6 |
Incorrect |
2142 ms |
514604 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |