Блог пользователя Vatsal38

Автор Vatsal38, история, 4 года назад, По-английски

solution link: https://ideone.com/Dn2nQN problem link : https://mirror.codeforces.com/problemset/problem/1234/B2 Why it is giving tle at 23rd case?

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Most likely it is because you are using an unordered map. Some tests are made specifically to mess with that container. Try using a map instead.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Yeah it worked thanks ! but why was it not working with unordered map. they are faster right?

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Unordered maps are faster? Can you tell me why this is so in the first place?

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        In map data is stored in sorted order while in unordered map it is not. operations like insert delete takes log n in map while o(1) in unordered

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If you want more information on unordered_map and how to make it faster: https://mirror.codeforces.com/blog/entry/62393

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Unordered map can have a high complexity when it is used a lot of times.