Language: C++

//ある区間が条件を満たすならば、
//それを包含する上位区間も条件を満たす問題を解くクラス
template <typename T>
class abstract_inchworm_superset
{
private:
    virtual void move_left_pointer() = 0;//lを右に動かす処理
    virtual void move_right_pointer() = 0;//rを右に動かす処理
    virtual bool is_cond() = 0; //条件成立か否かを返す
    virtual bool is_right_end() = 0;//rが右端に到達したかを返す
    virtual std::pair<T, T> no_next() = 0;//次の要素がない場合に終了値を返す
    virtual std::pair<T, T> get_LR() = 0;//lとrを返す
public:
    virtual std::pair<T, T> next(); //条件を満たすデータを返し、ポインタを次に進める
};
 
template <typename T>
std::pair<T, T> abstract_inchworm_superset<T>::next(){
    while (is_cond() == false && is_right_end() == false) {
            move_right_pointer();
    }
    if (is_cond() == false)
        return no_next();
    std::pair<T, T> ret = get_LR();
    move_left_pointer();
    return ret;
}
 
//ある区間が条件を満たすならば、
//それが包含する部分区間も条件を満たす問題を解くクラス
template <typename T>
class abstract_inchworm_subset
{
private:
    virtual void move_left_pointer() = 0;//lを右に動かす処理
    virtual void move_right_pointer() = 0;//rを右に動かす処理
    virtual bool is_cond() = 0; //条件成立か否かを返す
    virtual bool is_right_end() = 0;//rが右端に到達したかを返す
    virtual std::pair<T, T> no_next() = 0;//次の要素がない場合に終了値を返す
    virtual std::pair<T, T> get_LR() = 0;//lとrを返す
    virtual bool is_left_eq_right() = 0;
public:
    virtual std::pair<T, T> next(); //条件を満たすデータを返し、ポインタを次に進める
};
 
template <typename T>
std::pair<T, T> abstract_inchworm_subset<T>::next() {
    std::pair<T, T> ret;
    while (is_right_end() == false && is_cond() == true) {
        move_right_pointer();
    }
    ret = get_LR();
    if (is_left_eq_right() == true) {
        return no_next();
    }
    
    move_left_pointer();
    return ret;
}
 
#include <vector>
#include <stdio.h>
class xor_sum :
    public abstract_inchworm_subset<int>
{
private:
    int Left, Right;
    
    int N;
    long long LR_XOR;
    long long LRsum;
    std::vector<long long> sequence;

    virtual void move_left_pointer();
    virtual void move_right_pointer();
    virtual bool is_cond();
    virtual bool is_right_end();
    virtual std::pair<int, int> no_next();
    virtual std::pair<int, int> get_LR();
    virtual bool is_left_eq_right();
public:
 
    xor_sum(std::vector<long long>& sequence, int N, int start);
};
 
xor_sum::xor_sum(std::vector<long long>& sequence, int N, int start) :
    sequence(sequence),
    N(N),
    Left(start),
    Right(start),
    LR_XOR(0),
    LRsum(0)
{
}
 
 
void xor_sum::move_left_pointer() {
    LRsum -= sequence[Left];
    LR_XOR ^= sequence[Left];
    Left++;
 
}
 
void xor_sum::move_right_pointer() {
    if (Right < N) {
        LRsum += sequence[Right];
        LR_XOR ^= sequence[Right];
        Right++;
    }
}
 
bool xor_sum::is_cond() {
    if (Left >= N) 
        return false;
    //Rightが1つ先に行っても条件を満たすか
    if ((LRsum + sequence[Right]) == (LR_XOR ^ sequence[Right]))
        return true;
    return false;
}
 
bool xor_sum::is_right_end() {
    if (Right >= N)
        return true;
    return false;
}
 
std::pair<int, int> xor_sum::no_next() {
    return std::make_pair(-1, -1);
}
 
std::pair<int, int> xor_sum::get_LR() {
    return std::make_pair(Left, Right);
}
 
bool xor_sum::is_left_eq_right() {
    return (Left == Right);
}
 
 
int main()
{
    int N;
    std::vector<long long> A;
    scanf("%d", &N);
 
    for (int i = 0; i < N; i++) {
        long long a;
        scanf("%lld", &a);
        A.push_back(a);
    }
    xor_sum xs(A, N, 0);
    long long count = 0;
    while (1) {
        std::pair<int, int> LR = xs.next();
        if (LR.first == -1) break;
        count += LR.second - LR.first ;
    }
    printf("%lld\n", count);
    return 0;
}

Compiler output:
a.cc:11:18: error: 'pair' in namespace 'std' does not name a template type
   11 |     virtual std::pair<T, T> no_next() = 0;//次の要素がない場合に終了値を返す
      |                  ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | //ある区間が条件を満たすならば、
a.cc:12:18: error: 'pair' in namespace 'std' does not name a template type
   12 |     virtual std::pair<T, T> get_LR() = 0;//lとrを返す
      |                  ^~~~
a.cc:12:13: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
   12 |     virtual std::pair<T, T> get_LR() = 0;//lとrを返す
      |             ^~~
a.cc:14:18: error: 'pair' in namespace 'std' does not name a template type
   14 |     virtual std::pair<T, T> next(); //条件を満たすデータを返し、ポインタを次に進める
      |                  ^~~~
a.cc:14:13: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
   14 |     virtual std::pair<T, T> next(); //条件を満たすデータを返し、ポインタを次に進める
      |             ^~~
a.cc:18:6: error: 'pair' in namespace 'std' does not name a template type
   18 | std::pair<T, T> abstract_inchworm_superset<T>::next(){
      |      ^~~~
a.cc:18:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
   18 | std::pair<T, T> abstract_inchworm_superset<T>::next(){
      | ^~~
a.cc:39:18: error: 'pair' in namespace 'std' does not name a template type
   39 |     virtual std::pair<T, T> no_next() = 0;//次の要素がない場合に終了値を返す
      |                  ^~~~
a.cc:39:13: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
   39 |     virtual std::pair<T, T> no_next() = 0;//次の要素がない場合に終了値を返す
      |             ^~~
a.cc:40:18: error: 'pair' in namespace 'std' does not name a template type
   40 |     virtual std::pair<T, T> get_LR() = 0;//lとrを返す
      |                  ^~~~
a.cc:40:13: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
   40 |     virtual std::pair<T, T> get_LR() = 0;//lとrを返す
      |             ^~~
a.cc:43:18: error: 'pair' in namespace 'std' does not name a template type
   43 |     virtual std::pair<T, T> next(); //条件を満たすデータを返し、ポインタを次に進める
      |                  ^~~~
a.cc:43:13: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
   43 |     virtual std::pair<T, T> next(); //条件を満たすデータを返し、ポインタを次に進める
      |             ^~~
a.cc:47:6: error: 'pair' in namespace 'std' does not name a template type
   47 | std::pair<T, T> abstract_inchworm_subset<T>::next() {
      |      ^~~~
a.cc:47:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
   47 | std::pair<T, T> abstract_inchworm_subset<T>::next() {
      | ^~~
a.cc: In function 'int main()':
a.cc:154:37: error: 'class xor_sum' has no member named 'next'
  154 |         std::pair<int, int> LR = xs.next();
      |                                     ^~~~