Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pq;
typedef vector<pq> vpq;

ll sch(vll &v, ll key, int st, int ed)
{
    if (ed - st + 1 <= 1000)
    {
        for (int i = st; i < ed + 1; i++)
        {
            if (v[i] >= key)
            {
                return v[i];
            }
        }
        return -1;
    }

    int mid = (st + ed + 1) / 2;
    if (v[mid] >= key)
    {
        return search(v, key, st, mid);
    }
    else
    {
        return search(v, key, mid, ed);
    }
}

int main()
{
    string s, t;
    cin >> s >> t;

    vvll v('z' - 'a' + 1);
    for (ll i = 0; i < s.length(); i++)
    {
        char ch = s[i];
        int idx = ch - 'a';
        v[idx].push_back(i);
    }

    for (int i = 0; i < 'z' - 'a' + 1; i++)
    {
        sort(v[i].begin(), v[i].end());
    }

    ll ans = 0;
    ll len = s.length();
    ll lim = len * 1000;
    for (ll i = 0; i < t.length(); i++)
    {
        char ch = t[i];
        int idx = ch - 'a';

        bool flg = false;
        ll key = ans % len;
        ll tmp = -1;
        if (v[idx].size() > 0)
        {
            // key以上で最小の値を探す
            tmp = sch(v[idx], key, 0, v[idx].size() - 1);
            if (tmp == -1)
            {
                // なければ、key以下で最小の値を探す
                tmp = sch(v[idx], 0, 0, v[idx].size() - 1);
            }
            if (tmp != -1)
            {
                while (tmp + 1 <= ans)
                {
                    tmp += len;
                }
                if (tmp + 1 <= lim)
                {
                    flg = true;
                }
            }
        }
        if (flg)
        {
            ans = tmp + 1;
        }
        else
        {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'll sch(vll&, ll, int, int)':
a.cc:33:22: error: no matching function for call to 'search(vll&, ll&, int&, int&)'
   33 |         return search(v, key, st, mid);
      |                ~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note: candidate: 'template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> _ForwardIterator1 std::search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note:   candidate expects 5 arguments, 4 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: candidate: 'template<class _FIter1, class _FIter2> _FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2)'
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4090:5: note:   template argument deduction/substitution failed:
a.cc:33:22: note:   deduced conflicting types for parameter '_FIter1' ('std::vector<long long int>' and 'long long int')
   33 |         return search(v, key, st, mid);
      |                ~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note: candidate: 'template<class _ForwardIterator, class _Searcher> _ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&)'
 4184 |     search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note:   candidate expects 3 arguments, 4 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
  112 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note:   candidate expects 6 arguments, 4 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2)'
  117 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note:   candidate expects 5 arguments, 4 provided
a.cc:37:22: error: no matching function for call to 'search(vll&, ll&, int&, int&)'
   37 |         return search(v, key, mid, ed);
      |                ~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note: candidate: 'template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> _ForwardIterator1 std::search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note:   candidate expects 5 arguments, 4 provided
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: candidate: 'template<class _FIter1, class _FIter2> _FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2)'
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4090:5: note:   template argument deduction/substitution failed:
a.cc:37:22: note:   deduced conflicting types for parameter '_FIter1' ('std::vector<long long int>' and 'long long int')
   37 |         return search(v, key, mid, ed);
      |                ~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note: candidate: 'template<class _ForwardIterator, class _Searcher> _ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&)'
 4184 |     search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
  112 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note:   candidate expects 6 arguments, 4 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2)'
  117 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note:   candidate expects 5 arguments, 4 provided