Submission #721021

#TimeUsernameProblemLanguageResultExecution timeMemory
721021drdilyorDistributing Candies (IOI21_candies)C++17
0 / 100
5018 ms8132 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++) { auto check = [&](int x)->pair<bool,pair<int,int>> { int sum = real[i]; int low = sum, high = sum; for (int j = q-1; j >= x; j--) { if (l[j] <= i && i <= r[j]) { sum -= v[j]; } low = min(low, sum); high = max(high, sum); } return {high - low >= c[i], {high, low}}; }; int l = -1, r = q; while (l < r - 1) { int mid = (l + r) / 2; if (check(mid).first) l = mid; else r = mid; } if (l == -1) { res[i] = real[i] < 0 ? c[i] - real[i] : real[i]; } else { auto [_, bounds] = check(l); if (v[l] < 0) res[i] = c[i] - (bounds.first - real[i]); else res[i] = real[i] - bounds.second; } debug(check(0)); } return res; } /* █████ █████ ███ ████ ▒▒███ ▒▒███ ▒▒▒ ▒▒███ ███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████ ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒ ███ ▒███ ▒▒██████ ▒▒▒▒▒▒ */

Compilation message (stderr)

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:6:24: warning: statement has no effect [-Wunused-value]
    6 |     #define debug(...) 42
      |                        ^~
candies.cpp:57:9: note: in expansion of macro 'debug'
   57 |         debug(check(0));
      |         ^~~~~
#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...