frank1369blogger's blog

By frank1369blogger, history, 4 years ago, In English

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!

  • Vote: I like it
  • +7
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +9 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it +15 Vote: I do not like it

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 years ago, # |
  Vote: I like it +9 Vote: I do not like it

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).