Submission #620168

#TimeUsernameProblemLanguageResultExecution timeMemory
620168drdilyorDistributing Candies (IOI21_candies)C++17
0 / 100
3099 ms8148 KiB
#include <bits/stdc++.h> #include"candies.h" #ifdef ONPC #include "t_debug.cpp" #else #define debug(...) 42 #endif #define sz(a) ((int)(a).size()) using namespace std; using ll = long long; const int INF = 1e9; const ll INFL = 1e18; const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rng(RANDOM); template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; } const int N = 2e5, LOGN = 17, MOD = 1e9+7; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { int n = sz(c), q = sz(l); vector<int> res(n), real(n + 1); for (int i = 0; i < q; i++) { real[l[i]] += v[i]; real[r[i]+1] -= v[i]; } for (int i = 1; i < n; i++) real[i] += real[i-1]; for (int i = 0; i < n; i++) { int cur = real[i], low = cur, high = cur; for (int j = q-1; j >= 0; j--) { if (!(l[j] <= i && i <= r[j])) continue; cur -= v[j]; if (cur < low) { low = cur; if (high - low >= c[i]) { res[i] = c[i] - (high - real[i]); break; } } else if (cur > high) { high = cur; if (high - low >= c[i]) { res[i] = real[i] - low; break; } } } if (high - low < c[i]) { res[i] = real[i]; } } return res; } /* █████ █████ ███ ████ ▒▒███ ▒▒███ ▒▒▒ ▒▒███ ███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████ ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒ ███ ▒███ ▒▒██████ ▒▒▒▒▒▒ */
#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...