Language: C++

#include <bits/stdc++.h>
using namespace std ;
const int MAXN = 200005 ;
int L[MAXN]/**每个块的左端点*/,R[MAXN]/**每个块的右端点*/ ;
int pos[MAXN]/**每个点属于那个块*/ ;
int tagAdd[MAXN] ;
bool isAssigned[MAXN] ;
int mins[MAXN] ;
int n,m,k,bLen/**每个块大小*/,bCnt/**块的个数*/ ;
int data[MAXN] ;

int ans ;
void Init(int n)
{
    bLen = (int)sqrt(max(1.0*n,1.5)) ;
    bCnt = n/bLen ;
    R[0] = 0;
    ans = 0x3f3f3f3f ;
    for(int i(1);i<=bCnt;++i) {
        L[i] = R[i-1]+1;R[i] = i*bLen;
        isAssigned[i] = 0 ;
        mins[i] = 0 ;
        for(int j(L[i]);j<=R[i];++j) {
            pos[j] = i ;
        }
    }
    if(R[bCnt]!=n)///不完整的块的处理
        L[++bCnt]=R[bCnt-1]+1,R[bCnt] = n;
    for(int i(L[bCnt]);i<=R[bCnt];++i) pos[i] = bCnt ;
}

inline int calc(int i) {
    int p(pos[i]) ;
    if(isAssigned[p]) {
        return tagAdd[p] + (i - L[p] + 1) ;
    } else {
        return tagAdd[p] + data[i] ;
    }
}

void update(int l,int r)
{

    int pl(pos[l]), pr(pos[r]) ;

    int base = calc(l - 1) + R[pl] - l + 1 ;
    for(int i = 1;i <= bCnt; ++ i) {
        if (pl < i && i < pr) {
            isAssigned[i] = true ;
            tagAdd[i] = base ;
            mins[i] = base + 1 ;
            base += R[i] - L[i] + 1 ;
        } else {
            ++ tagAdd[i]  ;
            ++ mins[i] ;
        }
        ans = min(ans, mins[i]) ;
    }

    int tmp = calc(l - 1) ;
    for(int i = L[pl];i <= R[pl]; ++ i) {
        if (i < l) {
            data[i] = calc(i) ;
        } else {
            data[i] = ++ tmp ;
        }
        ans = min(ans, data[i]) ;
    }
    isAssigned[pl] = false ;
    tagAdd[pl] = 0 ;

    tmp = calc(R[pr - 1]) ;
    for(int i = L[pr];i <= R[pr]; ++ i) {
        if (i > r) {
            data[i] = calc(i) ;
        } else {
            data[i] = ++ tmp ;
        }
        ans = min(ans, data[i]) ;
    }
    isAssigned[pr] = false ;
    tagAdd[pr] = 0 ;
}

int main()
{
    int h,w ;
    ios::sync_with_stdio(false) ;
    cin >> h >> w ;
    Init(w) ;
    for(int i = 1;i <= h; ++ i) {
        int l, r ;
        cin >> l >> r ;
        update(l ,r) ;
        cout << ans << endl ;
    }
}


Compiler output:
a.cc: In function 'int calc(int)':
a.cc:37:28: error: reference to 'data' is ambiguous
   37 |         return tagAdd[p] + data[i] ;
      |                            ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:5: note:                 'int data [200005]'
   10 | int data[MAXN] ;
      |     ^~~~
a.cc: In function 'void update(int, int)':
a.cc:63:13: error: reference to 'data' is ambiguous
   63 |             data[i] = calc(i) ;
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:5: note:                 'int data [200005]'
   10 | int data[MAXN] ;
      |     ^~~~
a.cc:65:13: error: reference to 'data' is ambiguous
   65 |             data[i] = ++ tmp ;
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:5: note:                 'int data [200005]'
   10 | int data[MAXN] ;
      |     ^~~~
a.cc:67:24: error: reference to 'data' is ambiguous
   67 |         ans = min(ans, data[i]) ;
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:5: note:                 'int data [200005]'
   10 | int data[MAXN] ;
      |     ^~~~
a.cc:75:13: error: reference to 'data' is ambiguous
   75 |             data[i] = calc(i) ;
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:5: note:                 'int data [200005]'
   10 | int data[MAXN] ;
      |     ^~~~
a.cc:77:13: error: reference to 'data' is ambiguous
   77 |             data[i] = ++ tmp ;
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:5: note:                 'int data [200005]'
   10 | int data[MAXN] ;
      |     ^~~~
a.cc:79:24: error: reference to 'data' is ambiguous
   79 |         ans = min(ans, data[i]) ;
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:5: note:                 'int data [200005]'
   10 | int data[MAXN] ;
      |     ^~~~