#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;
}
#ifndef ONLINE_JUDGE
int main() {
int n;
assert(1 == scanf("%d", &n));
std::vector<int> c(n);
for(int i = 0; i < n; ++i) {
assert(scanf("%d", &c[i]) == 1);
}
int q;
assert(1 == scanf("%d", &q));
std::vector<int> l(q), r(q), v(q);
for(int i = 0; i < q; ++i) {
assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
}
std::vector<int> ans = distribute_candies(c, l, r, v);
for(int i = 0; i < n; ++i) {
if (i > 0) {
printf(" ");
}
printf("%d", ans[i]);
}
printf("\n");
fclose(stdout);
return 0;
}
#endif
/*
3
10 15 13
2
0 2 20
0 2 -11
*/
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();
| ^
/usr/bin/ld: /tmp/ccVhPyqc.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccXUtR3b.o:candies.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status