Language: C++

#include <functional>
#include <vector>
template <typename T>
class abstract_inchworm
{
protected:
    virtual void move_left_pointer() = 0;
    virtual void move_right_pointer() = 0;
    virtual bool is_cond() = 0; //条件成立を返す
    virtual bool is_right_end() = 0;
    virtual std::pair<T, T> no_next() = 0;
    virtual std::pair<T, T> get_LR() = 0;

public:
    virtual std::pair<T, T> next() = 0; //条件を満たすデータを返し、ポインタを次に進める

    virtual ~abstract_inchworm();
};

template <typename T>
abstract_inchworm<T>::~abstract_inchworm()
{
}



//ある区間が条件を満たすならば、
//それが包含する部分区間も条件を満たす問題を解くクラス
template <typename T>
class abstract_inchworm_subset :
    public abstract_inchworm<T>
{
protected:
    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;// = get_LR();
    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;
}



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;
protected:
    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;
    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);

}

#include <stdio.h>
#include <algorithm>
#include <time.h> 

//#define SEQUENCE
//#define CHOKUSETSU
#define XORSUM
int main()
{
#ifdef SEQUENCE

    int N;
    std::cin >> N;
    for (int k = 0; k < N; k++) {
        std::vector<long long> sequence;
        int n;
        long long S;
        std::cin >> n >> S;
        for (int i = 0; i < n; i++) {
            long long a;
            std::cin >> a;
            sequence.push_back(a);
        }

        subsequence seq(sequence, sequence.size(), 0);
        seq.set_S(S);
        int min_len = INT_MAX;
        while (1) {
            std::pair<int, int> LR = seq.next();
            if (LR.first == -1) break;
            min_len = std::min(min_len, LR.second - LR.first);
        }
        if (min_len == INT_MAX)
            std::cout << 0 << std::endl;
        else
            std::cout << min_len << std::endl;
    }
#else 
#ifdef CHOKUSETSU
    clock_t tic = clock();
    int P;
    scanf("%d", &P);
    std::vector<int> pages;
    std::map<int, int> item_list;
    for (int i = 0; i < P; i++) {
        int a;
        scanf("%d", &a);
        pages.push_back(a);
        item_list[a] = 0;
    }
    int r = 0;
    int l = 0;
    int read_item_num = 0;
    int min_len = INT_MAX;
    while (1) {
        while (read_item_num < item_list.size() && r < P) {
            int item = pages[r];
            if (item_list[item] == 0)
                read_item_num++;
            item_list[item]++;
            r++;
        }
        if (read_item_num < item_list.size()) break;

        min_len = std::min(min_len, r - l);

        int item = pages[l];
        item_list[item]--;
        if (item_list[item] == 0)
            read_item_num--;
        l++;
    }
    printf("%d\n", min_len);

    clock_t toc = clock();
    printf("%d\n", toc - tic);
#else
#ifdef XORSUM
    int N;
    std::vector<long long> A;
    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        int a;
        scanf("%d", &a);
        A.push_back(a);
    }
    xor_sum xs(A, N, 0);
    int count = 0;
    while (1) {
        std::pair<int, int> LR = xs.next();
        if (LR.first == -1) break;
        count += LR.second - LR.first ;
    }
    printf("%d\n", count);

#else
    clock_t tic = clock();
    std::vector<int> pages;
    
    int P;
    scanf("%d", &P);
    
    for (int i = 0; i < P; i++) {
        int a;
        scanf("%d", &a);
        pages.push_back(a);
    }
    reading rd(pages, P, 0);
    //reading rd;
    int min_len = INT_MAX;
    while (1) {
        std::pair<int, int> LR = rd.next();
        if (LR.first == -1) break;
        min_len = std::min(min_len, LR.second - LR.first);
    }
    printf("%d\n", min_len);
    clock_t toc = clock();
    printf("%d\n", toc - tic);
    return 0;
#endif
#endif
#endif
}


Compiler output:
a.cc: In member function 'virtual std::pair<T, T> abstract_inchworm_subset<T>::next()':
a.cc:42:12: error: there are no arguments to 'is_right_end' that depend on a template parameter, so a declaration of 'is_right_end' must be available [-fpermissive]
   42 |     while (is_right_end() == false && is_cond() == true) {
      |            ^~~~~~~~~~~~
a.cc:42:12: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:42:39: error: there are no arguments to 'is_cond' that depend on a template parameter, so a declaration of 'is_cond' must be available [-fpermissive]
   42 |     while (is_right_end() == false && is_cond() == true) {
      |                                       ^~~~~~~
a.cc:44:9: error: there are no arguments to 'move_right_pointer' that depend on a template parameter, so a declaration of 'move_right_pointer' must be available [-fpermissive]
   44 |         move_right_pointer();
      |         ^~~~~~~~~~~~~~~~~~
a.cc:46:11: error: there are no arguments to 'get_LR' that depend on a template parameter, so a declaration of 'get_LR' must be available [-fpermissive]
   46 |     ret = get_LR();
      |           ^~~~~~
a.cc:48:16: error: there are no arguments to 'no_next' that depend on a template parameter, so a declaration of 'no_next' must be available [-fpermissive]
   48 |         return no_next();
      |                ^~~~~~~
a.cc:50:5: error: there are no arguments to 'move_left_pointer' that depend on a template parameter, so a declaration of 'move_left_pointer' must be available [-fpermissive]
   50 |     move_left_pointer();
      |     ^~~~~~~~~~~~~~~~~