제출 #581868

#제출 시각아이디문제언어결과실행 시간메모리
581868adrilen사탕 분배 (IOI21_candies)C++17
0 / 100
99 ms7628 KiB
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int maxn = 2e5; const int maxc = 1e9; const int siz = (1 << 3); int segment_tree[siz * 2 + 1] = { 0 }; void update(int pos, pii wan, pii sear, int val) { if (wan.first > sear.second || sear.first > wan.second) return ; if (wan.first <= sear.first && sear.second <= wan.second) { segment_tree[pos] += val; return ; } int mid = (sear.first + sear.second) / 2; update(pos * 2, wan, pii(sear.first, mid), val); update(pos * 2 + 1, wan, pii(mid + 1, sear.second), val); } void calc(vector <int> &out, int pos, vector <int> &maxval, int val) { if (pos >= siz) { out[pos - siz] = min(maxval[pos - siz], val + segment_tree[pos]); } else { val = min(maxc, val + segment_tree[pos]); calc(out, pos * 2, maxval, val); calc(out, pos * 2 + 1, maxval, val); } } vector <int> positive(vector <int> &c, vector<int> &l, vector<int> &r, vector<int> &v) { int n = c.size(), q = v.size(); for (int i = 0; i < q; i++) { update(1, pii(l[i], r[i]), pii(0, siz - 1), v[i]); } vector <int> out(siz); calc(out, 1, c, 0); out.resize(n); return out; } vector<int> distribute_candies(vector <int> c, vector<int> l, vector<int> r, vector<int> v) { vector <int> s = positive(c, l, r, v); 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...