Submission #871306

#TimeUsernameProblemLanguageResultExecution timeMemory
871306TAhmed33Weirdtree (RMI21_weirdtree)C++17
8 / 100
2048 ms20536 KiB
#include <bits/stdc++.h> #include <weirdtree.h> using namespace std; typedef long long ll; int n; ll arr[300001]; void initialise (int N, int q, int h[]) { n = N; 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++) { if (arr[i] < 0) return; 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] = dd[i - 1].first - y; k %= i; sort(dd.begin(), dd.begin() + i, [] (pair <ll, ll> &a, pair <ll, ll> &b) { return a.second < b.second; }); for (int j = 0; j < k; j++) arr[dd[j].second]--; return; } } void magic (int i, int x) { } ll inspect (int l, int r) { ll sum = 0; for (int i = l; i <= r; i++) { if (arr[i] < 0) return 0; sum += arr[i]; } return sum; }/* int main () { int n, q; cin >> n >> q; int arr2[n + 1] = {}; for (int i = 1; i <= n; i++) { cin >> arr2[i]; } initialise(n, q, arr2); while (q--) { int k; cin >> k; if (k == 1) { int l, r, x; cin >> l >> r >> x; cut(l, r, x); } else { int l, r; cin >> l >> r; cout << inspect(l, r) << '\n'; } } }*/
#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...