#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#include "candies.h"
#endif
#include <vector>
#ifndef ONLINE_JUDGE
#include <vector>
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v);
#endif
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define ll long long
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll result(ll cap, vector<int> v) {
int q = v.size();
ll cur = 0;
for(int i=0; i<q; i++) {
cur += v[i];
cur = min(cur, cap);
cur = max(cur, 0ll);
}
return cur;
}
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
int n = c.size();
int q = v.size();
std::vector<int> s(n);
ll lb = 0, rb = 2e14;
while(lb < rb) {
ll mid = (lb + rb + 1) >> 1;
ll res = result(mid, v);
if(res == 0) lb = mid;
else rb = mid - 1;
}
ll lz = lb; // last zero
lb = lz + 1, rb = 2e14;
while(lb < rb) {
ll mid = (lb + rb) >> 1;
ll dis = result(mid, v);
ll prv = result(mid - 1, v);
if(dis == prv) rb = mid;
else lb = mid + 1;
}
ll one = result(lb, v);
ll two = result(lb - 1, v);
ll se; // start equal
if(one == two) se = lb;
else se = 2e14;
for(int i=0; i<n; i++) {
if(c[i] <= lz) s[i] = 0;
else {
if(c[i] >= se) c[i] = se - 1;
s[i] = c[i] - lz;
}
}
return s;
}
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:34:7: warning: unused variable 'q' [-Wunused-variable]
34 | int q = v.size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
168 ms |
12964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |