제출 #1024341

#제출 시각아이디문제언어결과실행 시간메모리
1024341HappyCapybara사탕 분배 (IOI21_candies)C++17
0 / 100
735 ms56040 KiB
#include "candies.h" #include <bits/stdc++.h> using namespace std; int n, k; vector<vector<int>> st; void merge(int node, vector<int> v){ st[node][0] = max(0, min(k, st[node][0]+v[2])); st[node][1] = max(0, min(k, st[node][1]+v[2])); st[node][0] = max(st[node][0], v[0]); st[node][1] = min(st[node][1], v[1]); st[node][2] += v[2]; } void prop(int node){ merge(node*2, st[node]); merge(node*2+1, st[node]); st[node] = {0, k, 0}; } void update(int l, int r, vector<int> v, int node=1, int tl=0, int tr=n-1){ if (l <= tl && tr <= r){ merge(node, v); return; } prop(node); int tm = (tl+tr)/2; if (l <= tm) update(l, r, v, node*2, tl, tm); if (tm+1 <= r) update(l, r, v, node*2+1, tm+1, tr); } vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){ n = c.size(); k = c[0]; int q = l.size(); st.resize(4*n, {0, k, 0}); for (int i=0; i<q; i++) update(l[i], r[i], {max(0, min(k, v[i])), max(0, min(k, k-v[i])), v[i]}); vector<int> s(n, 0); for (int i=0; i<n; i++){ int cur = 1, tl = 0, tr = n-1; while (tl != tr){ int tm = (tl+tr)/2; if (i <= tm){ cur = cur*2; tr = tm; } else { cur = cur*2+1; tl = tm+1; } } while (cur){ s[i] = max(st[cur][0], min(st[cur][1], s[i]+st[cur][2])); cur >>= 1; } } return s; }
#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...