# | User | Rating |
---|---|---|

1 | tourist | 3686 |

2 | LHiC | 3330 |

3 | wxhtxdy | 3329 |

4 | mnbvmar | 3296 |

5 | Benq | 3294 |

6 | sunset | 3279 |

7 | V--o_o--V | 3275 |

8 | ecnerwala | 3220 |

9 | yutaka1999 | 3190 |

10 | xyz111 | 3147 |

# | User | Contrib. |
---|---|---|

1 | Radewoosh | 190 |

1 | Errichto | 190 |

3 | rng_58 | 163 |

4 | PikMike | 158 |

5 | Vovuh | 157 |

6 | 300iq | 154 |

7 | Petr | 153 |

8 | Um_nik | 146 |

9 | majk | 145 |

10 | Swistakk | 143 |

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/26/2019 08:07:57 (e3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Can someone elaborate how to solve the third subtask in seats problem.

`3. (20 points) H <= 1000, W <= 1000, Q <= 5000`

Thanks in advance.

SpoilerMy approach: Let

B_{k}be the bounding box of all numbers from 1 tok.If

area(B_{k}) =k, thenB_{k}is beautiful. Conversely, ifRis a beautiful rectangle andarea(R) =k, thenarea(B_{k}) =k. And finally, ifarea(B_{k}) =k, thenarea(B_{k + 1}) >k, because ifR=B_{k}is beautiful, then eitherR_{k + 1}orC_{k + 1}is outside of the bounding boxB_{k}. Without loss of generality let it beR_{k + 1}. It follows thatk+ 1 is the first contestant at rowR_{k + 1}.So, all we need to remember is the contestant with the lowest id that is in the row

i, and the contestant with the lowest id that is in the columnj. We can do this by simply maintaining an ordered set of the indices of contestants for each row and column. This can be maintained in per query. Using this, we obtainH+Wcandidates on the beautiful rectangles inO(H+W) time and we simply check all of them.To check a candidate for a rectangle, we have a segment tree for calculating the minimum/maximum row/column on a range. This gives us time algorithm to process one query.

Combined together, this is .

To check a candidate for a rectangle, we have a segment tree for calculating the minimum/maximum row/column on a range. -> we can improve it to O(H+W) easily. (update r1, r2, c1, c2). Overall time complexity is O(HW + Q(H+W)).

Can you explain more on how it can be improved?

Would 10^7 segtree operations really pass?

My solution involves just iterating all the positions and recomputing for each query. You will get a total of 37 points with this.

SolutionLets define a beautiful box

B_{k}as a box containing only numbers 0 to k-1 I would sore in array`arr[id] = {r, c}`

the position of each contestant. Then for a bounding boxB_{k}to exist the prefix`arr[0..k]`

should form a rectangle. For that I get the min/max for column/row in the prefix of size`k`

and check if the rectangle is exactly of area`k`

. If yes then that is one box. So I compute this inO(HW) and build an array stating ifB_{k}is a bounding box or not. When each query arrives I will update positions`a`

and`b`

and recompute the positions of the array in the range`a`

and`b`

inO(|a-b|).Someone help me problem werewolf :D . I don't have any idea about this problem

Read the editorial at the official IOI website.

LooOoOoOOOooOoLooOooOooOooL. LMAO. ROFL.

Are you even too lazy to google that?

nopeeeee. i attemp many times but i don't find :D

I tried solving the fifth subtask of the problem seats (H = 1), but after reading the editorial I cannot understand how to use the lazy propagation segment tree to solve this. Can someone explain little bit on how to do this. Thanks in advance.

I can try this but I'm not sure if it is correct. Let's color cells which contains numbers 1 — x black others are white. Condition for this to be beautiful rectangle is that the (number of white cells which are adjacent to black cells should be <= 2). We have to maintain this value for each prefix.

Building : Let current number be 'x' and its position be 'pos'. Consider three case — both neighbour cells are black or one of them is black or none of them is black. For 1st case subtract 2. For 2nd case do nothing. For 3rd case add 2 to prefix 1-x.

Updates : Let two values that are swapped are 'sm' and 'lg'. sm is smaller of them. Consider 'sm' cell. Let its initial neighbours be val_11, val_12. If val_11 is greater than 'sm' subtract 1 from prefix(1,val_11). Same of val_12. Let its final neighbours be val_21, val_22. If they are greater than 'sm' add +1 to their prefixes. Do the same for larger value 'lg'. Update prefix (1-sm) & (1-lg) seperately.

Query : Check how many prefixes follow to above condition. You can easily check necessity and sufficiency of the condition.

Thank you for your reply, just to ask, in your update function by val_11 and val_12 do you mean the left and right neighbours of the current position?

Yes.