Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
    string S;
    cin >> S;
    deque<char> dS(S.size());
    for (int i = 0; i < S.size(); ++i) dS[i] = S[i];

    int Q; cin >> Q;
    int rev = 0;
    for (int i = 0; i < Q; ++i) {
        int type; cin >> type;
        if (type == 2) {
            int f; char c;
            cin >> f >> c; --f;
            if (rev) f = 1 - f; // 反転状態だったら、フラグを反転
            if (f == 0) dS.insert(0,c);
            else dS.insert(S.end(),c);
        }
        else rev = 1 - rev;
    }
    if (rev) reverse(dS.begin(), dS.end());
    for (auto c : dS) cout << c;
    cout << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:34: error: no matching function for call to 'std::deque<char>::insert(int, char&)'
   18 |             if (f == 0) dS.insert(0,c);
      |                         ~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:139,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_deque.h:1730:9: note: candidate: 'template<class _InputIterator, class> std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = char; _Alloc = std::allocator<char>]'
 1730 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1730:9: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/deque:69:
/usr/include/c++/14/bits/deque.tcc:210:5: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator; value_type = char]'
  210 |     deque<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/deque.tcc:212:27: note:   no known conversion for argument 1 from 'int' to 'std::deque<char>::const_iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::const_iterator'}
  212 |     insert(const_iterator __position, const value_type& __x)
      |            ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1661:7: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator; value_type = char]'
 1661 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1661:29: note:   no known conversion for argument 1 from 'int' to 'std::deque<char>::const_iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::const_iterator'}
 1661 |       insert(const_iterator __position, value_type&& __x)
      |              ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1675:7: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator]'
 1675 |       insert(const_iterator __p, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1675:29: note:   no known conversion for argument 1 from 'int' to 'std::deque<char>::const_iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::const_iterator'}
 1675 |       insert(const_iterator __p, initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_deque.h:1694:7: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator; size_type = long unsigned int; value_type = char]'
 1694 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1694:7: note:   candidate expects 3 arguments, 2 provided
a.cc:19:27: error: no matching function for call to 'std::deque<char>::insert(std::__cxx11::basic_string<char>::iterator, char&)'
   19 |             else dS.insert(S.end(),c);
      |                  ~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1730:9: note: candidate: 'template<class _InputIterator, class> std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = char; _Alloc = std::allocator<char>]'
 1730 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1730:9: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/deque.tcc:210:5: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator; value_type = char]'
  210 |     deque<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/deque.tcc:212:27: note:   no known conversion for argument 1 from 'std::__cxx11::basic_string<char>::iterator' to 'std::deque<char>::const_iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::const_iterator'}
  212 |     insert(const_iterator __position, const value_type& __x)
      |            ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1661:7: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator; value_type = char]'
 1661 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1661:29: note:   no known conversion for argument 1 from 'std::__cxx11::basic_string<char>::iterator' to 'std::deque<char>::const_iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::const_iterator'}
 1661 |       insert(const_iterator __position, value_type&& __x)
      |              ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1675:7: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator]'
 1675 |       insert(const_iterator __p, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1675:29: note:   no known conversion for argument 1 from 'std::__cxx11::basic_string<char>::iterator' to 'std::deque<char>::const_iterator' {aka 'std::_Deque_base<char, std::allocator<char> >::const_iterator'}
 1675 |       insert(const_iterator __p, initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_deque.h:1694:7: note: candidate: 'std::deque<_Tp, _Alloc>::iterator std::deque<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = char; _Alloc = std::allocator<char>; iterator = std::_Deque_base<char, std::allocator<char> >::iterator; const_iterator = std::_Deque_base<char, std::allocator<char> >::const_iterator; size_type = long unsigned int; value_type = char]'
 1694 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_deque.h:1694:7: note:   candidate expects 3 arguments, 2 provided