I have submitted this solution for This problem. I have done normal BFS traversal from both the ends. But I am getting TLe. What is wrong in my solution. Is it something like infinite loop. I am not able to figure it out.

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

1 | tourist | 3686 |

2 | LHiC | 3330 |

3 | wxhtxdy | 3329 |

4 | Benq | 3315 |

5 | Um_nik | 3301 |

6 | sunset | 3279 |

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

8 | yutaka1999 | 3190 |

9 | Radewoosh | 3179 |

10 | Petr | 3115 |

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

1 | Errichto | 193 |

2 | Radewoosh | 184 |

3 | rng_58 | 163 |

4 | PikMike | 162 |

5 | Vovuh | 157 |

6 | 300iq | 153 |

7 | Petr | 149 |

8 | Um_nik | 147 |

9 | neal | 144 |

9 | kostka | 144 |

I want to devise a data structure which should do these 2 queries in log(n) time

1 e : insert element e into the data structure

2 k find the number of elements strictly smaller than k in the data structure.

If I use multiset then I can use lower_bound to find the iterator but to convert it into index I need to use std::distance which runs in linear time. Like this

auto it = myMultiset.lower_bound(k); int numbeOfElements = distance(myMultiset.begin(), it);

How can I process the two queries in log(n) time

An array is given containing n elements which might contain duplicates. How to find the total number of distinct subsets of this array. If we find the frequencies of all the elements, add 1 to them and then multiply all of them, we will get all the combinations of the set of frequency of all the elements in a subset. But how to account for order of elements.

Also once it is found now I want to find the number of distinct subsets if all the occurrences of particular element is removed from the array and hence not included in any subset. Since I want to find this for every element can this be done in O(1) for every element with the help of some preprocessing.

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/16/2019 18:13:13 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|