Блог пользователя HideAndSeek

Автор HideAndSeek, история, 3 года назад, По-английски

We receive an initial sum of money S and a vector of N pairs of integers where:

v[i].first = sum of money

v[i].second = starting day for daily payments of that amount

Example: S = 1000, v = {(100, 10), (50, 100)}

S will be equal to:

  • 1000 from Day 0 (today) to Day 9;
  • 900 (=1000-100) from Day 10 to Day 99;
  • 850 (=1000-100-50) from Day 100 onwards.

q queries:

Type1: Update(i, new_amount, new_day): v[i].first = new_amount && v[i].second = new_day

Type2: Get(idx): Print the value of S on day idx

Constraints * 1 <= N, q <= 10^5 * 1 <= S, v[i].**first** <= 10^9 * 1 <= v[i].**second**, idx <= 10^6 * 1 <= No of PaymentUpdate operations <= 500

Considered using a Fenwick Tree / Segment Tree but I'm not sure how it would work since the start date can change too in the Update method / I don’t understand how the index changes when we need to push a new date

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится