Problem p02726 (C++) — buggy submission, verdict: Runtime Error

// 28/03/2020
#include <bits/stdc++.h>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\\n");
#define en '\\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define in_fre freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node {
  ll val, pos;
};
struct OverloadedNode {
  ll val, pos;
  bool operator<(const OverloadedNode &rhs) const {
    if (val == rhs.val)
      return pos < rhs.pos;
    else
      return val < rhs.val;
  }
};
// Algos
template <typename T>
using Pbds =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// typedef
// tree<OverloadedNode,null_type,less<OverloadedNode>,rb_tree_tag,tree_order_statistics_node_update>OverloadedPbds;

// Number Theory
template <typename T> T BigMod(T b, T p, T m) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T> T ModInv(T b, T m) { return BigMod(b, m - 2, m); }
template <typename T> T gcd(T a, T b) {
  if (a < 0)
    return gcd(-a, b);
  if (b < 0)
    return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) {
  if (a < 0)
    return lcm(-a, b);
  if (b < 0)
    return lcm(a, -b);
  return a * (b / gcd(a, b));
}

// Geometry
template <typename T> T Dis(T x1, T y1, T x2, T y2) {
  return sqrt(SQR(x1 - x2) + SQR(y1 - y2));
}
template <typename T> T Angle(T x1, T y1, T x2, T y2) {
  return atan2(double(y1 - y2), double(x1 - x2));
}

/*Containers*/
// vector<ll>v;
// deque<ll>dq;
// stack<ll>stk;
// map<ll,ll>mp;
// unordered_map<ll,ll>ump;
// set<ll>st;
// multiset<ll>mst;
// unordered_set<ll>ust;
// unordered_multiset<ll>umst;
// priority_queue<ll,deque<ll>,greater<ll>>pq;
// Pbds<ll>ost;
/*OverLoaded Containers*/
// vector<OverloadedNode>v;
// deque<OverloadedNode>dq;
// stack<OverloadedNode>stk;
// map<OverloadedNode,OverloadedNode>mp;
// set<OverloadedNode>st;
// multiset<OverloadedNode>mst;
// priority_queue<OverloadedNode>pq;
// OverloadedPbds oost;
/*Global Variables*/

map<ll, ll> k;

int main() {
  _fastio ll n, x, y;
  cin >> n >> x >> y;
  ll l = min(x, y);
  ll r = max(x, y);
  for (ll i = 1; i < n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      if (i <= l && j >= r) {
        // cout<<i<<' '<<j<<' '<<(j-i)-(r-l)+1<<' '<<k[(j-i)-(r-l)+1]++<<en;
        ll d1 = (j - i) - (r - l) + 1;
        ll d2 = j - i;
        k[min(d1, d2)]++;

      } else if (i <= l && j <= r) {
        ll d1 = (l - i) + (r - j) + 1;
        ll d2 = j - i;
        k[min(d1, d2)]++;
      } else if (i >= l && j <= r) {
        ll d1 = i - l + r - j + 1;
        ll d2 = j - i;
        k[min(d1, d2)]++;
      } else if (i >= l && j >= r) {
        ll d1 = i - l + j - r + 1;
        ll d2 = j - i;
        k[min(d1, d2)]++;
      } else {
        // cout<<i<<' '<<j<<' '<<j-i<<' '<<k[j-i]++<<en;
        k[j - i]++;
      }
    }
  }
  for (ll i = 1; i <= n - 1; i++) {
    cout << k[i] << en;
  }

  return 0;
}


Error: 0

Fixed submission:

// 28/03/2020
#include <bits/stdc++.h>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\\n");
#define en '\\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define in_fre freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node {
  ll val, pos;
};
struct OverloadedNode {
  ll val, pos;
  bool operator<(const OverloadedNode &rhs) const {
    if (val == rhs.val)
      return pos < rhs.pos;
    else
      return val < rhs.val;
  }
};
// Algos
template <typename T>
using Pbds =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// typedef
// tree<OverloadedNode,null_type,less<OverloadedNode>,rb_tree_tag,tree_order_statistics_node_update>OverloadedPbds;

// Number Theory
template <typename T> T BigMod(T b, T p, T m) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T> T ModInv(T b, T m) { return BigMod(b, m - 2, m); }
template <typename T> T gcd(T a, T b) {
  if (a < 0)
    return gcd(-a, b);
  if (b < 0)
    return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) {
  if (a < 0)
    return lcm(-a, b);
  if (b < 0)
    return lcm(a, -b);
  return a * (b / gcd(a, b));
}

// Geometry
template <typename T> T Dis(T x1, T y1, T x2, T y2) {
  return sqrt(SQR(x1 - x2) + SQR(y1 - y2));
}
template <typename T> T Angle(T x1, T y1, T x2, T y2) {
  return atan2(double(y1 - y2), double(x1 - x2));
}

/*Containers*/
// vector<ll>v;
// deque<ll>dq;
// stack<ll>stk;
// map<ll,ll>mp;
// unordered_map<ll,ll>ump;
// set<ll>st;
// multiset<ll>mst;
// unordered_set<ll>ust;
// unordered_multiset<ll>umst;
// priority_queue<ll,deque<ll>,greater<ll>>pq;
// Pbds<ll>ost;
/*OverLoaded Containers*/
// vector<OverloadedNode>v;
// deque<OverloadedNode>dq;
// stack<OverloadedNode>stk;
// map<OverloadedNode,OverloadedNode>mp;
// set<OverloadedNode>st;
// multiset<OverloadedNode>mst;
// priority_queue<OverloadedNode>pq;
// OverloadedPbds oost;
/*Global Variables*/

ll k[20003];

int main() {
  _fastio ll n, x, y;
  cin >> n >> x >> y;
  ll l = min(x, y);
  ll r = max(x, y);
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (i <= l && j >= r) {
        k[(j - i) - (r - l) + 1]++;
      } else
        k[j - i]++;
    }
  }
  for (ll i = 1; i <= n - 1; i++) {
    cout << k[i] << en;
  }

  return 0;
}