It's so strange. I can never get to the link http://codeforces.com/problemset/problem/1304/D . But other links are OK. Can anyone tell me why or how I can solve it? Thank you.

Before contest

Codeforces Round #687 (Div. 1, based on Technocup 2021 Elimination Round 2)

37:15:10

Register now »

Codeforces Round #687 (Div. 1, based on Technocup 2021 Elimination Round 2)

37:15:10

Register now »

*has extra registration

Before contest

Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)

37:15:10

Register now »

Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)

37:15:10

Register now »

*has extra registration

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

1 | tourist | 3687 |

2 | ecnerwala | 3600 |

3 | Benq | 3503 |

4 | ksun48 | 3421 |

5 | Um_nik | 3412 |

6 | Radewoosh | 3382 |

7 | maroonrk | 3323 |

8 | Itst | 3239 |

9 | apiadu | 3238 |

10 | ko_osaga | 3232 |

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

1 | Errichto | 205 |

2 | SecondThread | 197 |

3 | Monogon | 195 |

4 | vovuh | 189 |

5 | Um_nik | 186 |

6 | pikmike | 185 |

7 | antontrygubO_o | 184 |

8 | Ashishgup | 182 |

9 | pashka | 169 |

10 | Radewoosh | 167 |

**Why can we put the option onto a segment tree? What do the segment tree do?**

Thank you

**Hello!**

You may have met these kinds of problems that require you to calculate the prefix sum with modifying, and you can use a fenwick tree *SUM* in order to solve it. When you want to lower_bound on it, you can reference this way as follows: You wonder the minimum *index* in the array *SUM[L~R]* satisfied *SUM[index]≥K*.

Set l=0, r=R, mid=R three pointers as the left, right, middle. If log2(r-l) is a positive interger, mid = (r - l)/2, or mid = pow(2, ceil(r-l) ) + l. If SUM[mid]≥K, r = mid, or l = mid. Continue to do it if l < mid < r. In the end, index = mid.

For this algorithm, it's not difficult to prove that the time complexity is about log2(R). You can understand it better with the help of this picture. And also you can solve such problems with a segment tree If there is something wrong with my algorithm, please tell me. Thanks.

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Nov/27/2020 20:49:50 (h3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|