Codeforces Round #340 (Div. 2) Editorial

Правка en4, от komendart, 2016-01-23 21:17:57

It's first version of editorial. I will try to expand it and correct mistakes.

617A - Elephant

It's optimal to do the biggest possible step everytime. So elephant should do several steps by distance 5 and one or zero step by smaller distance. Answer equals to

Solution

617B - Chocolate

We are given array which contains only ones and zeroes. We must divide it on parts with only one 1.

Tricky case: when array contains only zeroes answer equals to 0.

In general. Between two adjacent ones we must have only one separation. So, answer equals to product of values posi - posi - 1 where posi is position of i-th one.

Bonus: what's the maximal possible answer for n ≤ 100?

Solution

617C - Watering Flowers

First radius equals to zero or distance from first fountain to some flower. Let's iterate over this numbers. Second radius equals to maximal distance from second fountain to flower which doesn't belong to circle with first radius. Now we should choose variant with minimal r12 + r22.

Bonus: It's O(n2) solution. Can you solve problem in O(nlogn)?

Solution O(n^2)

Solution O(nlogn)

617D - Polyline

Answer equals to one if all coordinates x or y of points are same.

When answer equals to two? Let's iterate over all pairs of points. Let first point in pair is beginning of polyline, second point is end. Only one or two such polylines with answer two exist. If third point is on the polyline it belongs to rectangle with corners in first two points. We can just check it.

Else answer equals to three. We can build vertical lines which contains the most left and the most right point and horizontal line through third point. If we erase some excess rays we will get polyline.

Solution

617E - XOR and Favorite Number

We have array a.

Let's calculate array pref (pref[0] = 0, ).

Xor of subarray a[l...r] equals to .

So query (l, r) is counting number of pairs i, j (l - 1 ≤ i < j ≤ r) .

Let we know answer for query (l, r) and know for all v cnt[v] — count of v in a[l - 1...r]. We can update in O(1) answer and cnt if we move left or right border of query on 1. So we can solve problem offline in with sqrt-decomposion (Mo's algorithm).

Solution

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
ru2 Русский komendart 2016-01-24 11:57:00 289
en5 Английский komendart 2016-01-24 11:51:18 363 Tiny change: 'wer for $n[Solution]$?\n\nSolu' - 100$?\n\nSolu'
ru1 Русский komendart 2016-01-24 11:38:19 3000 Первая редакция перевода на Русский
en4 Английский komendart 2016-01-23 21:17:57 274 Tiny change: 'XrpikpT)\n[Solutio' -
en3 Английский komendart 2016-01-23 21:00:09 23 Tiny change: ' expand it.\n\n[prob' - (published)
en2 Английский komendart 2016-01-23 20:56:47 230 Tiny change: 'uals to $\ceil{x/5}$' -
en1 Английский komendart 2016-01-23 20:41:01 2204 Initial revision (saved to drafts)