Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;

#define debug(args...)                                                         \\
  cout << "#" << __LINE__ << ": ";                                             \\
  __dbg(split(#args, ',').begin(), args);
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args> inline string to_str(T x) {
  stringstream ss;
  ss << "[";
  for (auto it = x.begin(); it != x.end(); it++) {
    if (it != x.begin())
      ss << " ";
    ss << (*it);
  }
  ss << "]";
  return ss.str();
}
template <typename T, typename... Args> inline string to_str(stack<T> x) {
  stringstream ss;
  ss << "[";
  bool first = 1;
  while (!x.empty()) {
    if (!first)
      ss << " ";
    ss << x.top();
    x.pop();
    first = 0;
  }
  ss << "]";
  return ss.str();
}
template <typename T> inline void __dbg_var(vector<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(list<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(set<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(unordered_set<T> x) {
  cout << to_str(x);
}
template <typename T> inline void __dbg_var(stack<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(T val) { cout << val; }
inline void __dbg(vector<string>::iterator it) { cout << endl; }
template <typename T, typename... Args>
inline void __dbg(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << "=";
  __dbg_var(a);
  cout << " ";
  __dbg(++it, args...);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll x, ans = 0;
  cin >> x;
  ll a[x];
  unordered_map<ll, ll> s;

  for (int i = 0; i < x; i++) {
    cin >> a[i];
    if (s.find(i - a[i]) != s.end())
      ans += s[i - a[i]];
    s[a[i] + i]++;
  }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;

#define debug(args...)                                                         \\
  cout << "#" << __LINE__ << ": ";                                             \\
  __dbg(split(#args, ',').begin(), args);
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args> inline string to_str(T x) {
  stringstream ss;
  ss << "[";
  for (auto it = x.begin(); it != x.end(); it++) {
    if (it != x.begin())
      ss << " ";
    ss << (*it);
  }
  ss << "]";
  return ss.str();
}
template <typename T, typename... Args> inline string to_str(stack<T> x) {
  stringstream ss;
  ss << "[";
  bool first = 1;
  while (!x.empty()) {
    if (!first)
      ss << " ";
    ss << x.top();
    x.pop();
    first = 0;
  }
  ss << "]";
  return ss.str();
}
template <typename T> inline void __dbg_var(vector<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(list<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(set<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(unordered_set<T> x) {
  cout << to_str(x);
}
template <typename T> inline void __dbg_var(stack<T> x) { cout << to_str(x); }
template <typename T> inline void __dbg_var(T val) { cout << val; }
inline void __dbg(vector<string>::iterator it) { cout << endl; }
template <typename T, typename... Args>
inline void __dbg(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << "=";
  __dbg_var(a);
  cout << " ";
  __dbg(++it, args...);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll x, ans = 0;
  cin >> x;
  ll a[x];

  for (int i = 0; i < x; i++)
    cin >> a[i];

  for (int i = 0; i < x; i++) {
    for (int j = i + 1; j < x; j++)
      if (j - i == a[i] + a[j])
        ans++;
  }
  cout << ans << "\\n";
  return 0;
}