#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] += v;
dif[r+1] -= v;
}
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]});
VI ans1 = TEST1::solve(c, qrs);
VI ans2 = TEST2::solve(c, qrs);
cout << "real answer: ";
for (int x : ans1) cout << x << " "; cout << endl;
cout << "my answer: ";
for (int x : ans2) cout << x << " "; cout << endl;
return VI(n, 0);
}
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();
| ^
candies.cpp: In function 'VI _distribute_candies(VI, VI, VI, VI)':
candies.cpp:84:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
84 | for (int x : ans1) cout << x << " "; cout << endl;
| ^~~
candies.cpp:84:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
84 | for (int x : ans1) cout << x << " "; cout << endl;
| ^~~~
candies.cpp:86:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
86 | for (int x : ans2) cout << x << " "; cout << endl;
| ^~~
candies.cpp:86:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
86 | for (int x : ans2) cout << x << " "; cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
4 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
14352 KB |
Output is correct |
2 |
Correct |
68 ms |
18584 KB |
Output is correct |
3 |
Correct |
67 ms |
18332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
35 ms |
9784 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
38 ms |
9804 KB |
Output isn't correct |
4 |
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 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Correct |
75 ms |
14352 KB |
Output is correct |
7 |
Correct |
68 ms |
18584 KB |
Output is correct |
8 |
Correct |
67 ms |
18332 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
35 ms |
9784 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |