| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 4 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 142 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| Название |
|---|



Second problem is solving by segment tree, and I guess that in first problem there is always answer n — 1)
n-1 is showing wrong for first question
ok
i got it, if sum of numbers is divisible by n then ans is n else n-1
Thanks
what's the logic behind this solution ?
you can make n-1 element equal by choosing a single element for decreasing.
If sum of numbers is divisible by n then all element changed to sum_element/n by choosing two index one with value greater than sum_element/n and other with smaller value at a time.
Can we solve "update the array" without use of segment tree
Also you can use Fenwick tree
Yes, it has an obvious solution without a segment tree. Let's make an array
add[n+1]initially with zeroes. Than for each update :add[l] += val; add[r + 1] -= val;How to reestablish the arraya[n]in our problem? Here is a simple code on c++ :Then for each query you just output a[i].
Thanks sokian
Generally, segment tree or fenwick tree is used when the array is updated and queried arbitrarily. i.e., Update is followed by query which is then followed by update.
In the second sum, there is first a number of updates. But after that, only querying and NO updates. So every element in its final state can be precomputed in O(n). For each query, it's then only O(1).
P.S.: Segment tree or Fenwick tree would also give the right answer but it would be slower and unnecessary.