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

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

hi. I wanted to know some basic information about vectors. I really like vectors more than arrays as they are easier to use. But the only problem is about the time. It rarely happens that vectors cause you TLE and when you change them to array it gets accepted. So I wanted to know what those cases exactly are and in witch problems should I start coding using arrays. Will be happy to hear your opinion if you have faced my problems and know how to fix them. Thanks!

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

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

I have personally never had a case where vector gave TLE and array gave AC

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

Vectors usually cause TLE if you use a lot of small vectors. If you only use big vectors, there shouldn't be a big difference in performance between arrays and vectors.

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

It happens in this case when you pass a large vector to a function without reference, the function creates a local copy of the large vector and time is consumed in the process while arrays are passed as reference by default, so in this particular case the execution is fast with arrays. So, I personally suggest that pass vectors by reference to any function(or make them const if no change is required to be made) to avoid ambiguous TLE. Or you can declare them globaly and directly access them in your functions(which people generally do).