Language: C++

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define H_MAX 80
#define W_MAX 80
#define VAL_MAX 80

int A[H_MAX][W_MAX], B[H_MAX][W_MAX];
char table[H_MAX][W_MAX][(H_MAX+W_MAX)*VAL_MAX];

map<long long int, vector<pair<long long int, long long int> >* > m;

void solv()
{
	long long int N, X, D; scanf("%lld%lld%lld", &N, &X, &D);

	if (0 == D){
		if (0 == X){
			printf("0");
		}
		else{
			printf("%d", N + 1);
		}

		return;
	}
	if (D < 0){
		D = -D;
		X = -X;
	}

	long long int left = 0, right = 0;
	for (int i = 0; i <= N; i++){
		if (m.end() == m.find((X*i) % D)){
			vector<pair<long long int, long long int> > *v = new vector<pair<long long int, long long int> >();
			m.insert(make_pair((X*i) % D, v));
		}
		vector<pair<long long int, long long int> > *v = m.find((X*i) % D)->second;
		v->push_back(make_pair(D*left + X*i, D*right + X*i));

		left += i;
		right += N - 1 - i;
	}
	
	long long int cnt = 0;
	for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
		sort(itr->second->begin(), itr->second->end());
		cnt += ((*itr->second)[0].second - (*itr->second)[0].first) / D + 1;
		long long int head = (*itr->second)[0].first, tail = (*itr->second)[0].second;
		for (int i = 1; i < itr->second->size(); i++){
			if (head <= (*itr->second)[i].first && (*itr->second)[i].first <= tail){
				if ((*itr->second)[i].second > tail){
					cnt += ((*itr->second)[i].second - tail) / D;
					tail = (*itr->second)[i].second;
				}
			}
			else{
				cnt += ((*itr->second)[i].second - (*itr->second)[i].first) / D + 1;
				head = (*itr->second)[i].first;
				tail = (*itr->second)[i].second;
			}
		}
	}

	printf("%lld", cnt);

	//for (map<int, vector<pair<int, int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
	//	delete itr->second;
	//	itr++;
	//}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Compiler output:
a.cc: In function 'void solv()':
a.cc:56:93: error: conversion from '_Rb_tree_iterator<pair<const long long int,[...]>>' to non-scalar type '_Rb_tree_iterator<pair<const int,[...]>>' requested
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                      ~~~~~~~^~
a.cc:56:101: error: no match for 'operator!=' (operand types are 'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} and 'std::map<long long int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const long long int, std::vector<std::pair<long long int, long long int> >*> >, std::less<long long int>, std::allocator<std::pair<const long long int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'})
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                 ~~~ ^~ ~~~~~~~
      |                                                                                                 |           |
      |                                                                                                 |           _Rb_tree_iterator<pair<const long long int,[...]>>
      |                                                                                                 _Rb_tree_iterator<pair<const int,[...]>>
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1052 |     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1052:5: note:   template argument deduction/substitution failed:
a.cc:56:110: note:   'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} is not derived from 'const std::pair<_T1, _T2>'
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                              ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  455 |     operator!=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:455:5: note:   template argument deduction/substitution failed:
a.cc:56:110: note:   'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                              ^
/usr/include/c++/14/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  500 |     operator!=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:500:5: note:   template argument deduction/substitution failed:
a.cc:56:110: note:   'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                              ^
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1686 |     operator!=(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note:   template argument deduction/substitution failed:
a.cc:56:110: note:   'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} is not derived from 'const std::move_iterator<_IteratorL>'
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                              ^
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1753 |     operator!=(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note:   template argument deduction/substitution failed:
a.cc:56:110: note:   'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} is not derived from 'const std::move_iterator<_IteratorL>'
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                              ^
In file included from /usr/include/c++/14/vector:63,
                 from a.cc:7:
/usr/include/c++/14/bits/allocator.h:243:5: note: candidate: 'template<class _T1, class _T2> bool std::operator!=(const allocator<_Tp1>&, const allocator<_T2>&)'
  243 |     operator!=(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/14/bits/allocator.h:243:5: note:   template argument deduction/substitution failed:
a.cc:56:110: note:   'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} is not derived from 'const std::allocator<_Tp1>'
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                              ^
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:2096:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator!=(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2096 |     operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:2096:5: note:   template argument deduction/substitution failed:
a.cc:56:110: note:   'std::map<int, std::vector<std::pair<long long int, long long int> >*>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, std::vector<std::pair<long long int, long long int> >*>, std::_Select1st<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> >, std::less<int>, std::allocator<std::pair<const int, std::vector<std::pair<long long int, long long int> >*> > >::iterator'} is not derived from 'const std::vector<_Tp, _Alloc>'
   56 |         for (map<int, vector<pair<long long int, long long int> >* >::iterator itr = m.begin(); itr != m.end(); itr++){
      |                                                                                                              ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,