Hi everyone, please consider the following submission:
https://mirror.codeforces.com/problemset/submission/1467/215118514
The code is in O(n), yet I'm getting TLE. I changed cin to scanf. In that I got my answer different on CF server and local machine. So, I changed it back to cin.
I don't think I'm calling too many functions. They all run in O(1) time.
When you pass a vector by value, it gets copied over. So the complexity is $$$O(n^2)$$$ and not $$$O(n)$$$.
use
vector<int>& v
in next time!I passed it by value because I wanted to make changes to the vector and not reflect it in the main function.
You can save the current value and restore later then the original in the main function will not be changed.
bool hov(int i, vector<ll> &v)
ll calc(int i, vector<ll> &v)
You can update the function signature like this and submit again.