Submission #1043459

#TimeUsernameProblemLanguageResultExecution timeMemory
1043459AmirAli_H1Distributing Candies (IOI21_candies)C++17
38 / 100
5043 ms14716 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...