Help me in solving ODDSUM problem

My issue

why its giving TLE i am doing it in O(n)

My code

#include <iostream>
using namespace std;

int main() {
    long long T;
    cin >> T;

    for (long long i = 0; i < T; i++) {
        long long N;
        long long ans = 0;
        cin >> N;
        if (N % 2 != 0) {
            
            ans = ((N - 1) / 2) % 2 == 0 ? N * (N - 1) / 2 + 1 : N * (N - 1) / 2;
        } else {
            ans = (N / 2) % 2 == 0 ? N * (N - 1) / 2 + 1 : N * (N - 1) / 2;
        }

        cout << ans << endl;
    }
    return 0;
}

Learning course: 1600 to 1800 difficulty problems
Problem Link: Odd Sum Practice Problem in - CodeChef

The editorial states:

This problem had rather high constraints - in most languages, the default method of taking input and printing output will likely time out, and the statement had a note asking participants to use faster methods.

However, there is one more pitfall here, specifically in C++ - and that is the use of endl.
The standard way of speeding up i/o in C++ via adding the lines

ios::sync_with_stdio(0);
cin.tie(0);

speeds up output by ensuring that the output buffer is not flushed every time cin is called (which is what cin.tie(0) does).
However, endl always forces a flush of the buffer, so using it essentially nullifies any benefit you had in the first place.
The workaround is to always use \n instead of endl .

You can solve it in O(1) time.
1+(n-2)*(n-1)
Use fast i/o additionally