# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
728068 | stevancv | Distributing Candies (IOI21_candies) | C++17 | 408 ms | 38460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "candies.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const int mod = 1e9 + 7;
ll sum[4 * N], mn[4 * N], mx[4 * N];
void Add(int node, int l, int r, int x, int y) {
if (l == r) {
sum[node] += y; mn[node] = mx[node] = sum[node];
return;
}
int mid = l + r >> 1;
if (x <= mid) Add(2 * node, l, mid, x, y);
else Add(2 * node + 1, mid + 1, r, x, y);
sum[node] = sum[2 * node] + sum[2 * node + 1];
mn[node] = min(mn[2 * node], sum[2 * node] + mn[2 * node + 1]);
mx[node] = max(mx[2 * node], sum[2 * node] + mx[2 * node + 1]);
}
int Solve(int node, int l, int r, int x) {
if (l == r) return max(0ll, min((ll)x, sum[node]));
int mid = l + r >> 1;
if (mx[2 * node + 1] - mn[2 * node + 1] > x) return Solve(2 * node + 1, mid + 1, r, x);
int o = Solve(2 * node, l, mid, x);
if (o + mn[2 * node + 1] < 0) return sum[2 * node + 1] - mn[2 * node + 1];
Compilation message (stderr)
# | 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... |