Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
int n,d,a,siz=1;
P p[800010];
vector<int> dat[800010],laz[800010];
void init(int x){
    while(siz<x)siz*=2;
    dat.resize(2*siz-1,0);
    laz.resize(2*siz-1,0);
    for(int i=0;i<n;i++)dat[i+siz-1]=p[i].se;
    for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
}
void eval(int k,int l,int r){
    dat[k]+=laz[k];
    if(r-l>1){
        laz[k*2+1]+=laz[k]/2;
        laz[k*2+2]+=laz[k]/2;
    }
    laz[k]=0;
}
void update(int a,int b,int x,int k=0,int l=0,int r=-1){
    if(r==-1)r=siz;
    eval(k,l,r);
    if(r<=a||b<=l)return;
    if(a<=l&&r<=b){
        laz[k]=(r-l)*x;
        eval(k,l,r);
        return;
    }
    update(a,b,x,k*2+1,l,(l+r)/2);
    update(a,b,x,k*2+2,(l+r)/2,r);
}
int query(int a,int k=0,int l=0,int r=-1){
    if(r==-1)r=siz;
    eval(k,l,r);
    if(r-l==1)return dat[k];
    if(a<(l+r)/2)return query(a,k*2+1,l,(l+r)/2);
    return query(a,k*2+2,(l+r)/2,r);
}
signed main(){
    cin>>n>>d>>a;
    rep(i,n){
        cin>>p[i].fi>>p[i].se;
        p[i].se=(p[i].se-1)/a+1;
    }
    sort(p,p+n);
    int h[200010];
    rep(i,n)h[i]=p[i].fi;
    init(n);
    int ans=0;
    rep(i,n){
        int q=query(i);
        if(q>0){
            ans+=q;
            update(i,upper_bound(h,h+n,h[i]+d+d)-h,-q);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'void init(long long int)':
a.cc:15:9: error: request for member 'resize' in 'dat', which is of non-class type 'std::vector<long long int> [800010]'
   15 |     dat.resize(2*siz-1,0);
      |         ^~~~~~
a.cc:16:9: error: request for member 'resize' in 'laz', which is of non-class type 'std::vector<long long int> [800010]'
   16 |     laz.resize(2*siz-1,0);
      |         ^~~~~~
a.cc:8:12: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'long long int')
    8 | #define se second
      |            ^~~~~~
a.cc:17:43: note: in expansion of macro 'se'
   17 |     for(int i=0;i<n;i++)dat[i+siz-1]=p[i].se;
      |                                           ^~
In file included from /usr/include/c++/14/vector:72,
                 from a.cc:3:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'long long int' to 'const std::vector<long long int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'long long int' to 'std::vector<long long int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'long long int' to 'std::initializer_list<long long int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:18:47: error: no match for 'operator+' (operand types are 'std::vector<long long int>' and 'std::vector<long long int>')
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                     ~~~~~~~~~~^~~~~~~~~~~
      |                                              |          |
      |                                              |          vector<[...]>
      |                                              vector<[...]>
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'const std::reverse_iterator<_Iterator>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'const std::move_iterator<_IteratorL>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   mismatched types 'const _CharT*' and 'std::vector<long long int>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:18:57: note:   'std::vector<long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   18 |     for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
      |                                                         ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string