#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define mod 998244353
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll ksm(ll a, ll b) {if (b == 0) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
using namespace std;
const int maxn = 200005;
int n, q;
vi a(maxn);
vi brute_force(vi c, vi l, vi r, vi v) {
for (int i = 0; i < q; i++) {
for (int j = l[i]; j <= r[i]; j++) {
if (v[i] > 0) a[j] = min(c[j], a[j] + v[i]);
else a[j] = max(0, a[j] + v[i]);
}
}
return a;
}
vi all_positive(vi c, vi l, vi r, vi v) {
vector<ll> pref(n);
for (int i = 0; i < q; i++) {
pref[l[i]] += v[i];
if (r[i] < n - 1) pref[r[i] + 1] -= v[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum += pref[i];
a[i] = min(c[i], sum);
}
return a;
}
vi distribute_candies(vi c, vi l, vi r, vi v) {
n = (int) c.size();
q = (int) l.size();
a.resize(n);
if (n <= 1000 && q <= 1000) {
return brute_force(c, l, r, v);
}
if (*min_element(v.begin(), v.end()) > 0) {
return all_positive(c, l, r, v);
}
}
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:1: warning: control reaches end of non-void function [-Wreturn-type]
53 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
12744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Incorrect |
64 ms |
8168 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Incorrect |
62 ms |
8180 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |