Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll MAX=200041;
const ll INF=0x3f3f3f3f;
ll b[MAX],next[MAX],c0[MAX],c1[MAX],dist[MAX],N,Q;
pii op[MAX];
struct section{
    ll l,r,val;
};
stack<section> rec;
void cpush(section x){
    rec.push(x);
    section tmp1,tmp2;
    while(rec.size()>=2){
        tmp1=rec.top(); rec.pop();
        tmp2=rec.top(); rec.pop();
        if(tmp1.r>=tmp2.l){
            rec.push({tmp1.l,tmp2.r,min(tmp1.val,tmp2.val)});
        }
        else{
            rec.push(tmp2),rec.push(tmp1);
            return;
        }
    }

}
int main(){
    scanf("%lld",&N);
    for(ll i=1;i<=N;i++) scanf("%lld",&b[i]);
    scanf("%lld",&Q);
    for(ll i=1;i<=Q;i++) scanf("%lld%lld",&op[i].first,&op[i].second),op[i].second++;
    op[Q+1]=make_pair(N+1,N+1);
    op[0]=make_pair(1,1);
    for(ll i=N;i>=1;i--){
        c0[i]=c0[i+1],c1[i]=c1[i+1];
        if(b[i]) c1[i]++;
        else c0[i]++;
    }
    sort(op+1,op+Q+1);
    for(ll i=Q+1;i>=1;i--){
        for(ll j=op[i-1].first+1;j<=op[i].first;j++) next[j]=i;
    }
    for(ll i=Q;i>=0;i--){
        dist[i]=INF;
        ll t1=c1[op[i].second]-c0[op[i].second]-c1[op[next[op[i].second]].first]+dist[next[op[i].second]];
        cpush({op[i].first,op[i].second,t1});
        section tmp=rec.top();
        dist[i]=min(c0[op[i].first]+tmp.val,c1[op[i].first]-c1[op[i+1].first]+dist[i+1]);

        //printf("%d %d %d %d\n",i,op[i].first,op[i].second,next[op[i].second]);
        //printf("%d\n",dist[i]);

    }
    printf("%lld\n",dist[0]);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:54: error: reference to 'next' is ambiguous
   43 |         for(ll j=op[i-1].first+1;j<=op[i].first;j++) next[j]=i;
      |                                                      ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:11: note:                 'll next [200041]'
    7 | ll b[MAX],next[MAX],c0[MAX],c1[MAX],dist[MAX],N,Q;
      |           ^~~~
a.cc:47:55: error: reference to 'next' is ambiguous
   47 |         ll t1=c1[op[i].second]-c0[op[i].second]-c1[op[next[op[i].second]].first]+dist[next[op[i].second]];
      |                                                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:11: note:                 'll next [200041]'
    7 | ll b[MAX],next[MAX],c0[MAX],c1[MAX],dist[MAX],N,Q;
      |           ^~~~
a.cc:47:87: error: reference to 'next' is ambiguous
   47 |         ll t1=c1[op[i].second]-c0[op[i].second]-c1[op[next[op[i].second]].first]+dist[next[op[i].second]];
      |                                                                                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:11: note:                 'll next [200041]'
    7 | ll b[MAX],next[MAX],c0[MAX],c1[MAX],dist[MAX],N,Q;
      |           ^~~~