// In the name of Allah
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include "candies.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define endl '\n'
#define sep ' '
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define pb push_back
#define Mp make_pair
const int maxn = 2e5 + 4;
int n, q;
int A[maxn]; pair<pii, int> Q[maxn];
int val[maxn]; vector<int> ans;
void solve1() {
for (int i = 0; i < q; i++) {
int l = Q[i].F.F, r = Q[i].F.S, x = Q[i].S;
for (int j = l; j < r; j++) val[j] += x;
for (int j = l; j < r; j++) val[j] = (val[j] >= 0) ? val[j] : 0;
for (int j = l; j < r; j++) val[j] = (val[j] <= A[j]) ? val[j] : A[j];
}
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
n = len(c); q = len(l);
for (int i = 0; i < n; i++) A[i] = c[i];
for (int i = 0; i < q; i++) Q[i] = Mp(Mp(l[i], r[i] + 1), v[i]);
fill(val, val + n, 0);
solve1();
ans.clear(); ans.resize(n);
for (int i = 0; i < n; i++) ans[i] = val[i];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4167 ms |
14716 KB |
Output is correct |
2 |
Correct |
4348 ms |
12156 KB |
Output is correct |
3 |
Correct |
4340 ms |
12160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2644 KB |
Output is correct |
2 |
Correct |
68 ms |
8148 KB |
Output is correct |
3 |
Correct |
68 ms |
7748 KB |
Output is correct |
4 |
Correct |
4223 ms |
12156 KB |
Output is correct |
5 |
Correct |
4297 ms |
12156 KB |
Output is correct |
6 |
Correct |
4380 ms |
12160 KB |
Output is correct |
7 |
Correct |
4198 ms |
12112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
132 ms |
8132 KB |
Output is correct |
4 |
Correct |
132 ms |
6724 KB |
Output is correct |
5 |
Execution timed out |
5043 ms |
10576 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
4167 ms |
14716 KB |
Output is correct |
7 |
Correct |
4348 ms |
12156 KB |
Output is correct |
8 |
Correct |
4340 ms |
12160 KB |
Output is correct |
9 |
Correct |
0 ms |
2644 KB |
Output is correct |
10 |
Correct |
68 ms |
8148 KB |
Output is correct |
11 |
Correct |
68 ms |
7748 KB |
Output is correct |
12 |
Correct |
4223 ms |
12156 KB |
Output is correct |
13 |
Correct |
4297 ms |
12156 KB |
Output is correct |
14 |
Correct |
4380 ms |
12160 KB |
Output is correct |
15 |
Correct |
4198 ms |
12112 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
132 ms |
8132 KB |
Output is correct |
19 |
Correct |
132 ms |
6724 KB |
Output is correct |
20 |
Execution timed out |
5043 ms |
10576 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |