#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
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();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
12808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
36 ms |
9920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
33 ms |
9904 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Incorrect |
69 ms |
12808 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |