This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
VI 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();
rep(i, n) setmin(dif[i], c[i]);
return dif;
}
};
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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |