Cout<<endl l vs "\n" C++ and time limit exceeding error

This is a very serious issue that today I wrote 130 lines of segment tree code and found that it was giving TLE and couldn’t find the way out and got demotivated but when I replaced my cout<<endl with cout<<“/n” it gave an AC. Can someone tell me about this, why did it happen ??

My code before replacing with endl >>CodeChef: Practical coding for everyone

When I replaced the 124th line with “\n” it gave AC?? Should I now always use cout<<“\n” ???

Use cout << “\n”;