#include "candies.h"
#include <bits/stdc++.h>
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ve = vector <T>;
template <typename T>
bool umx (T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T>
bool umn (T& a, T b) { return a > b ? a = b, 1 : 0; }
using ll = long long;
using ld = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
using ull = unsigned long long;
const int oo = 1e9;
const ll OO = 1e18;
const int N = 2e5 + 10;
const int M = 5e3 + 100;
const int mod = 1e9 + 7;
const bool TEST = 0;
ll T[4 * N];
void push(int v) {
if(!T[v]) return;
T[v << 1] += T[v];
T[v << 1 | 1] += T[v];
T[v] = 0;
}
void add(int v, int tl, int tr, int l, int r, int x) {
if (l > r) return;
if (l == tl && r == tr) {
T[v] += x;
return;
}
push(v);
int tm = (tl + tr) >> 1;
add(v << 1, tl, tm, l, min(r, tm), x);
add(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r, x);
}
ll get(int v, int tl, int tr, int ps) {
if (tl == tr) return T[v];
int tm = (tl + tr) >> 1;
push(v);
if (ps > tm) return get(v << 1 | 1, tm + 1, tr, ps);
else return get(v << 1, tl, tm, ps);
}
vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
int n = c.size();
int q = v.size();
bool ok = 1;
bool ok1 = 1;
for (int i = 0; i < q; i++) ok &= (v[i] > 0);
for (int i = 0; i < q; i++) ok1 &= (c[i] == c[0]);
vector<int> s(n);
if (ok) {
for (int i = 0; i < q; i++) {
add(1, 0, n - 1, l[i], r[i], v[i]);
}
for (int i = 0 ; i < n; i++) {
s[i] = min(ll(c[i]), get(1, 0, n - 1, i));
}
return s;
}
if (n <= 2000 && q <= 2000) {
for (int i = 0; i < q; i++) {
for (int j = l[i]; j <= r[i]; j++) {
s[j] += v[i];
umx(s[j], 0);
umn(s[j], c[j]);
}
}
return s;
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
182 ms |
11468 KB |
Output is correct |
2 |
Correct |
161 ms |
15544 KB |
Output is correct |
3 |
Correct |
163 ms |
15292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
44 ms |
4984 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
43 ms |
4968 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
182 ms |
11468 KB |
Output is correct |
7 |
Correct |
161 ms |
15544 KB |
Output is correct |
8 |
Correct |
163 ms |
15292 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
44 ms |
4984 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |