1. STL template Efficiency
Generally, the STL template causesProgramThe running efficiency slows down because some standard data structures in the STL template need to allocate a large amount of memory space and context switching overhead. Sometimes containers such as vector are running, in case of insufficient capacity, it is very time-consuming to repeatedly allocate larger memory and copy the original content.
In addition, if you use the STL templateMake sure that a data structure is shared globally.Otherwise, the memory will be re-allocated each time a local data structure is defined, which is very time-consuming.
This is essentially the concept. Try to apply for a good memory space before running the program. do not apply continuously during the program running. In this way, the system requires constant context switching overhead.In addition, for containers that dynamically allocate storage space like a vector, if the problem permits the amount, the space size is predefined directly..
2. input and output efficiency
When there is a large number of input and output, do not use stream input and output, otherwise the program execution speed is very restrained.
You can use the input and output operations in C language. (I compared the two Input and Output Modes in a program with large input and output, and found that using the C language output input function increases the program execution speed by nearly 800 ms)
If you have time, sort it out: