Submission #871298

#TimeUsernameProblemLanguageResultExecution timeMemory
871298TAhmed33Weirdtree (RMI21_weirdtree)C++17
0 / 100
5 ms2908 KiB
#include <bits/stdc++.h> #include <weirdtree.h> using namespace std; typedef long long ll; int n; ll arr[1001]; void initialise (int N, int q, int h[]) { n = N; assert(n <= 1000 && q <= 1000); for (int i = 1; i <= n; i++) { arr[i] = h[i]; } } void cut (int l, int r, int k) { vector <pair <ll, ll>> dd; ll sum = 0; for (int i = l; i <= r; i++) { dd.push_back({arr[i], i}); sum += arr[i]; } if (sum <= k) { for (int i = l; i <= r; i++) arr[i] = 0; return; } sort(dd.begin(), dd.end(), [] (pair <ll, ll> &a, pair <ll, ll> &b) { return a.first == b.first ? a.second < b.second : a.first > b.first; }); dd.push_back({0, (ll)1e9}); for (int i = 1; i < (int)dd.size(); i++) { if (dd[i].first == dd[i - 1].first) continue; ll t = (dd[i - 1].first - dd[i].first) * i; if (t <= k) { k -= t; continue; } ll y = k / i; for (int j = 0; j < i; j++) arr[dd[j].second] = y; k -= y; for (int j = 0; j < k; j++) arr[dd[j].second]--; return; } } void magic (int i, int x) { arr[i] = x; } ll inspect (int l, int r) { ll sum = 0; for (int i = l; i <= r; i++) sum += arr[i]; return sum; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...