[Sorry, I firstly misunderstood the question]Why not? Enumerate all squares. Assume that we have already visited some finite number of squares and are now placed in the boundary square (that is, one of its coordinates is either maximal or minimal between all visited squares), and also the number in it is maximal. Say, in the upper square. Consider the square with minimal number, which is not visited yet. Our local goal is to visit it. For this we go to the up far-far away, then to the right, then to the down, and then to the left(I omit some details here). So we have visited next square. Then go to the left and we are no in the leftmost square and number in it is also maximal. Another thing
I think, details are fairly simple at least in the case $a_n=n$. Indeed, if we must carry on is go up by $+n$, $+(n+1)$, $+(n+2)$, \dots, $+(n+k)$ we increase y-coordinate by $n+\dots+(n+k)$. We could replace $+s$ to $-s$, then we would get $2s$ less sum. So, by choosing $k$ and $s$ (we may use not only one $s$, but say 2 or three different values of $s$, but do not choose two consecutive $s$) we may get all numberssufficiently large $y$-coordinates, making at most 2 or 3 down jumps. AgainMoreover, choose even if $k$ is fixed we may get almost all coordinates of corresponding parity. Then we have the least not used number and do some work for placing it same freedom going to the right, then going down, and returning to the position left. Choose parities and jumps to "boundary opposite" directions for going to the necessary pointwith maximal used number".Well, this is not a rigorous proof, some technical details are really missed, but I do
For $a_n=n^2$ it should not expect difficulties herebe much harder.

