Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

const int DAT_SIZE=1<<18;
const int MAX_N=500050;
int N;

vll data(DAT_SIZE),datb(DAT_SIZE);
vll v(MAX_N);

//[a,b)にxを加算
//0-indexであることに注意
void add(int a,int b,ll x,int k=0,int l=0,int r=N){
    if(a<=l&&r<=b)data[k]+=x;
    else if(l<b&&a<r){
        datb[k]+=(ll)(min(b,r)-max(a,l))*x;
        add(a,b,x,2*k+1,l,(l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2,r);
    }
}

//初期化
void init(int n){
    N=1;
    while(N<n)N*=2;
    rep(i,n)add(i,i+1,v[i],0,0,n);
}

//[a,b)の和
//0-indexであることに注意
ll getsum(int a,int b,int k=0,int l=0,int r=N){
    if(b<=l||r<=a)return 0;
    else if(a<=l&&r<=b)return data[k]*(ll)(r-l)+datb[k];
    else{
        ll res=(ll)(min(b,r)-max(a,l))*data[k];
        res+=getsum(a,b,2*k+1,l,(l+r)/2);
        res+=getsum(a,b,2*k+2,(l+r)/2,r);
        return res;
    }
}

int main(){
    int n,q;cin>>n>>q;
    vin c(n);rep(i,n)cin>>c[i];
    vector<tuple<int,int,int>> query(q);
    int l,r;
    rep(i,q){
        cin>>l>>r;
        query[i]=make_tuple(r,l,i);
    }
    sort(all(query));
    init(n);
    int x,y,z;int tmp=0;
    vin prev(n+1,-1);
    vin ans(q);
    rep(i,q){
        y=get<0>(query[i]);
        x=get<1>(query[i]);
        z=get<2>(query[i]);
        rep2(j,tmp,y+1){
            add(prev[c[j]]+1,j,1);
            prev[c[j]]=j;
        }
        ans[i]=getsum(x,x+1);
    }
    rep(i,q)cout<<ans[i]<<endl;
}

Compiler output:
a.cc: In function 'void add(int, int, ll, int, int, int)':
a.cc:34:19: error: reference to 'data' is ambiguous
   34 |     if(a<=l&&r<=b)data[k]+=x;
      |                   ^~~~
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:28:5: note:                 'vll data'
   28 | vll data(DAT_SIZE),datb(DAT_SIZE);
      |     ^~~~
a.cc: In function 'll getsum(int, int, int, int, int)':
a.cc:53:31: error: reference to 'data' is ambiguous
   53 |     else if(a<=l&&r<=b)return data[k]*(ll)(r-l)+datb[k];
      |                               ^~~~
/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:28:5: note:                 'vll data'
   28 | vll data(DAT_SIZE),datb(DAT_SIZE);
      |     ^~~~
a.cc:55:40: error: reference to 'data' is ambiguous
   55 |         ll res=(ll)(min(b,r)-max(a,l))*data[k];
      |                                        ^~~~
/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:28:5: note:                 'vll data'
   28 | vll data(DAT_SIZE),datb(DAT_SIZE);
      |     ^~~~