classSolution: defdiscountPrices(self, s: str, discount: int) -> str: d = discount * 0.01 words = s.split(' ') ans = [] for word in words: cur = word if word[0] == '$'and word[1:].isnumeric(): cur = float(cur[1:]) * (1.0 - d) cur = format(cur, ".2f") cur = '$' + str(cur) ans.append(cur) ans = " ".join(ans) return ans
voidbuild(int u, int l, int r){ tr[u] = {l, r}; // tr[u].v = 0; if (l < r) { int mid = l + r >> 1; build(u + u, l, mid); build(u + u + 1, mid + 1, r); pushup(u); } }
intquery(int u, int l, int r){ if (tr[u].l == l and tr[u].r == r) return tr[u].v; int mid = tr[u].l + tr[u].r >> 1; int v = 0; if (r <= mid) v = query(u + u, l, r); elseif (l > mid) v = query(u + u + 1, l, r); else { v = max(query(u + u, l, mid), query(u + u + 1, mid + 1, r)); } return v; }
voidmodify(int u, int x, int c){ if (tr[u].l == x and tr[u].r == x) { tr[u].v = c; return ; }
int mid = tr[u].l + tr[u].r >> 1; if (x <= mid) modify(u + u, x, c); else modify(u + u + 1, x, c); pushup(u); }
classSolution { public: inttotalSteps(vector<int>& nums){ int n = nums.size(); vector<int> f(n + 1, 0), idx(n + 1, 0); stack<int> stk; for (int i = 1; i <= n; i ++ ) { int cur = nums[i - 1]; while (stk.size() and nums[stk.top() - 1] <= cur) stk.pop(); if (stk.size()) idx[i] = stk.top(); stk.push(i); } build(1, 1, n); for (int i = 1; i <= n; i ++ ) { if (idx[i] == 0) continue; // for (int j = idx[i] + 1; j < i; j ++ ) // ans = max(ans, f[j]); assert (idx[i] + 1 <= i); f[i] = query(1, idx[i] + 1, i) + 1; modify(1, i, f[i]); } return *max_element(f.begin(), f.end()); } };