#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
#define fi first
#define se second
#define left BAO
#define right ANH
#define pb push_back
#define pf push_front
#define mp make_pair
#define ins insert
#define btpc __builtin_popcount
#define btclz __builtin_clz
#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
template<class X, class Y>
bool minimize(X &x, const Y &y) {
if (x > y)
{
x = y;
return true;
}
return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
if (x < y)
{
x = y;
return true;
}
return false;
}
const int MOD = 1e9 + 7; //998244353
template<class X, class Y>
void add(X &x, const Y &y) {
x = (x + y);
if(x >= MOD) x -= MOD;
}
template<class X, class Y>
void sub(X &x, const Y &y) {
x = (x - y);
if(x < 0) x += MOD;
}
/* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/
const ll INF = 1e9;
const int N = 1e5 + 10;
template <class T> struct FenwickTree {
int n;
vector<T> bit;
FenwickTree(int _n = 0) {
n = _n;
bit.resize(n + 5);
for(int i = 1; i <= n; i++) bit[i] = 0;
}
void update(int pos, T x) {
for(int i = pos; i <= n; i += i & (-i)) bit[i] += x;
}
T get(int pos) {
T ans = 0;
for(int i = pos; i > 0; i -= i & (-i)) ans += bit[i];
return ans;
}
};
vector<int> distribute_candies(vector<int> c, vector<int> left, vector<int> right, vector<int> val) {
int n = c.size();
int q = left.size();
if(n <= 2000 && q <= 2000) {
vector<int> ans(n, 0);
for(int i = 0; i < q; i++) {
for(int j = left[i]; j <= right[i]; j++) {
ans[j] = min(c[j], ans[j] + val[i]);
ans[j] = max(0, ans[j]);
}
}
return ans;
}
bool isSub1 = true;
for(int i = 0; i < q; i++) isSub1 &= (val[i] > 0);
if(isSub1) {
FenwickTree<ll> BIT = FenwickTree<ll>(n);
for(int i = 0; i < q; i++) {
int l = left[i] + 1, r = right[i] + 1;
BIT.update(l, val[i]);
BIT.update(r + 1, -val[i]);
}
vector<int> ans(n);
for(int i = 0; i < n; i++) {
ll r = BIT.get(i + 1);
ans[i] = min(r, 1ll * c[i]);
}
return ans;
}
return {};
};
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
8900 KB |
Output is correct |
2 |
Correct |
107 ms |
12964 KB |
Output is correct |
3 |
Correct |
115 ms |
12772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
74 ms |
4964 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4976 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
125 ms |
8900 KB |
Output is correct |
7 |
Correct |
107 ms |
12964 KB |
Output is correct |
8 |
Correct |
115 ms |
12772 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
74 ms |
4964 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |