Submission #1050654

#TimeUsernameProblemLanguageResultExecution timeMemory
1050654ZicrusDistributing Candies (IOI21_candies)C++17
0 / 100
77 ms16720 KiB
#include <bits/stdc++.h> #include "candies.h" using namespace std; typedef long long ll; ll n, q; vector<pair<ll, ll>> cap; vector<pair<ll, ll>> tim; vector<ll> sum; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { n = c.size(); q = v.size(); cap = vector<pair<ll, ll>>(n); tim = {{n-1, 0}}; sum = vector<ll>(q+1); for (int i = 0; i < q; i++) { sum[i+1] = sum[i] + v[i]; } for (int i = 0; i < n; i++) { cap[i] = {c[i], i}; } sort(cap.begin(), cap.end()); for (int i = 0; i < q; i++) { ll mx = cap[tim.back().first].first; ll nw = sum[i+1] - sum[abs(tim.back().second)]; if (tim.back().second < 0) nw += mx; while (tim.size() > 1 && (nw < 0 || nw > mx)) { tim.pop_back(); nw = sum[i+1] - sum[abs(tim.back().second)]; if (tim.back().second < 0) nw += mx; } ll left = -1, right = tim.back().first; while (left < right) { ll mid = (left+right+1) / 2; ll v = sum[i+1] - sum[abs(tim.back().second)]; if (tim.back().second < 0) v += cap[mid].first; if (v < 0 || v > cap[mid].first) { left = mid; } else { right = mid-1; } } if (left == tim.back().first) tim.back().second = v[i] < 0 ? (i+1) : -(i+1); else if (left >= 0) tim.push_back({left, v[i] < 0 ? (i+1) : -(i+1)}); } vector<int> res(n); for (int i = 0; i < n; i++) { while (i > tim.back().first) tim.pop_back(); res[cap[i].second] = sum[q] - sum[abs(tim.back().second)]; if (tim.back().second < 0) res[cap[i].second] += cap[i].first; } 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...