#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "candies.h"
struct QUERY {
int l, r, v;
};
typedef vector<QUERY> VQ;
namespace TEST1 {
VI solve(VI c, VQ qrs) {
int n = c.size();
int q = qrs.size();
VI a(n);
for (auto[l, r, v] : qrs) {
replr(i, l, r) {
a[i] += v;
setmin(a[i], c[i]);
setmax(a[i], 0);
}
}
return a;
}
};
namespace TEST2 {
bool check(VQ qrs) {
for (auto[l, r, v] : qrs) if (v < 0) return false;
return true;
}
VI solve(VI c, VQ qrs) {
int n = c.size();
int q = qrs.size();
VL dif(n+1);
for (auto[l, r, v] : qrs) {
dif[l]++;
dif[r+1]--;
}
replr(i, 1, n) dif[i] += dif[i-1];
dif.pop_back();
VI ans(n);
rep(i, n) ans[i] = min(dif[i], 1ll*c[i]);
return ans;
}
};
VI distribute_candies(VI c, VI l, VI r, VI v) {
int n = c.size();
int q = l.size();
VQ qrs;
rep(i, q) qrs.pb({l[i], r[i], v[i]});
if (n <= 2000 && q <= 2000) return TEST1::solve(c, qrs);
if (TEST2::check(qrs)) return TEST2::solve(c, qrs);
return VI();
}
Compilation message
candies.cpp: In function 'VI TEST1::solve(VI, VQ)':
candies.cpp:42:13: warning: unused variable 'q' [-Wunused-variable]
42 | int q = qrs.size();
| ^
candies.cpp: In function 'VI TEST2::solve(VI, VQ)':
candies.cpp:61:13: warning: unused variable 'q' [-Wunused-variable]
61 | int q = qrs.size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
14492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
36 ms |
9824 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
33 ms |
9836 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Incorrect |
70 ms |
14492 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |