#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define st first
#define nd second
#define ll long long
#define LL node * 2
#define RR node * 2 + 1
#define N 300005
#define LOGN 20
const int modulo = 1e9 + 7;
const ll INF = 2e18 + 7;
ll tree[4 * N], lazy[4 * N], lazy_set[4 * N];
int arr[N];
void push(int node, int l, int r){
tree[node] += lazy[node];
if (lazy_set[node] != -1){
if (l == r){
if (lazy_set[node] == 1) tree[node] = arr[l];
else if (lazy_set[node] == 0) tree[node] = 0;
}
else{
lazy_set[LL] = lazy_set[node];
lazy_set[RR] = lazy_set[node];
}
}
if (l != r){
lazy[LL] += lazy[node];
lazy[RR] += lazy[node];
}
lazy[node] = 0;
lazy_set[node] = -1;
}
void build(int node, int l, int r){
tree[node] = 0;
lazy[node] = 0;
lazy_set[node] = -1;
if (l == r) return;
int mid = (l + r) / 2;
build(LL,l, mid);
build(RR, mid + 1, r);
}
void update1(int node, int l, int r, int sl, int sr, int val){
push(node, l, r);
if (l > sr || r < sl) return;
if (l >= sl && r <= sr){
lazy[node] += val;
push(node, l , r);
return;
}
int mid = (l + r) / 2;
update1(LL, l, mid, sl, sr, val);
update1(RR, mid + 1, r, sl, sr, val);
}
void update2(int node, int l, int r, int sl, int sr, int val){
push(node, l, r);
if (l > sr || r < sl) return;
if (l >= sl && r <= sr){
lazy_set[node] = val;
push(node, l, r);
return;
}
int mid = (l + r) / 2;
update2(LL, l, mid, sl, sr, val);
update2(RR, mid + 1, r, sl, sr, val);
}
ll query(int node, int l, int r, int sl){
push(node, l, r);
if (l > r || l > sl || r < sl) return 0;
if (l == r) {
return tree[node];
}
int mid = (l + r) / 2;
if (sl <= mid) return query(LL, l, mid, sl);
return query(RR, mid + 1, r, sl);
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = c.size();
vector<int> s(n, 0);
int m = l.size();
build(1, 0, n - 1);
for (int i = 0; i < n; i++){
for (int j = l[i]; j <= r[i]; j++){
int curr = max(0, min(s[j] + v[i], c[j]));
s[j] = curr;
}
}
return s;
}
/*
int main() {
fileio();
int n;
assert(1 == scanf("%d", &n));
std::vector<int> c(n);
for(int i = 0; i < n; ++i) {
assert(scanf("%d", &c[i]) == 1);
}
int q;
assert(1 == scanf("%d", &q));
std::vector<int> l(q), r(q), v(q);
for(int i = 0; i < q; ++i) {
assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
}
std::vector<int> ans = distribute_candies(c, l, r, v);
for(int i = 0; i < n; ++i) {
if (i > 0) {
printf(" ");
}
printf("%d", ans[i]);
}
printf("\n");
fclose(stdout);
return 0;
}*/
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:101:9: warning: unused variable 'm' [-Wunused-variable]
101 | int m = l.size();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5052 ms |
25940 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
12892 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Runtime error |
4 ms |
12892 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |