Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <unordered_map>
#include <queue>
#include <tuple>
#include <algorithm>

using namespace std;

template<typename T>
class PMA {
private:
    uint32_t id = 0;

public:
    struct Node {
        uint32_t id;
        bool accepted = false;
        unordered_map<T, Node*> children;
        Node *failure = nullptr;
    };

    Node *root;

    int32_t insert(const vector<T> &vec) {
        Node *node = root;
        for (T v : vec) {
            auto itr = node->children.find(v);
            if (itr != node->children.end()) {
                node = itr->second;
            } else {
                node->children[v] = new Node;
                node->children[v]->id = id++;
                node = node->children[v];
            }
        }

        node->accepted = true;

        return node->id;
    }

    Node *transition(Node *node, T v) {
        while (node != nullptr) {
            auto itr = node->children.find(v);
            if (itr != node->children.end()) {
                return itr->second;
            } else {
                node = node->failure;
            }
        }
        return root;
    }

    void link_failure() {
        queue<Node*> tovisit;
        tovisit.push(root);
        while (!tovisit.empty()) {
            Node *node = tovisit.front();
            tovisit.pop();

            for (auto p : node->children) {
                T v = p.first;
                Node *child = p.second;

                child->failure = transition(node->failure, v);

                tovisit.push(child);
            }
        }
        return;
    }

    PMA() {
        root = new Node;
        root->id = id++;
    }
};

int main() {
    int32_t H, W, R, C;
    scanf("%d %d\n", &H, &W);

    vector<vector<uint8_t>> T(H);
    for (int32_t r = 0; r < H; r++) {
        for (int32_t c = 0; c < W; c++) {
            T[i][j] = getchar();
        }
    }

    cin >> R >> C;

    vector<vector<uint8_t>> P(R);
    for (int32_t r = 0; r < R; r++) {
        for (int32_t c = 0; c < C; c++) {
            P[i][j] = getchar();
        }
    }

    PMA<uint8_t> pma_p;
    vector<uint32_t> M;
    for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
    pma_p.link_failure();

    PMA<uint32_t> pma_m;
    pma_m.insert(M);
    pma_m.link_failure();

    vector<vector<uint32_t>> T2(W);

    for (vector<uint8_t> vec : T) {
        PMA<uint8_t>::Node *node = pma_p.root;
        for (uint32_t i = 0; i < vec.size(); i++) {
            node = pma_p.transition(node, vec[i]);
            T2[i].push_back(node->id);
        }
    }

    vector<pair<uint32_t, uint32_t>> res;
    for (int32_t c = 0; c < W; c++) {
        PMA<uint32_t>::Node *node = pma_m.root;
        for (int32_t r = 0; r < H; r++) {
            node = pma_m.transition(node, T2[c][r]);
            if (node->accepted) {
                res.push_back(make_pair(r - R + 1, c - C + 1));
            }
        }
    }

    sort(res.begin(), res.end());

    for (auto p : res) printf("%d %d\n", p.first, p.second);

    return 0;
}

Compiler output:
a.cc:14:5: error: 'uint32_t' does not name a type
   14 |     uint32_t id = 0;
      |     ^~~~~~~~
a.cc:8:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    7 | #include <algorithm>
  +++ |+#include <cstdint>
    8 | 
a.cc:18:9: error: 'uint32_t' does not name a type
   18 |         uint32_t id;
      |         ^~~~~~~~
a.cc:18:9: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc: In member function 'int32_t PMA<T>::insert(const std::vector<_Tp>&)':
a.cc:34:41: error: 'id' was not declared in this scope
   34 |                 node->children[v]->id = id++;
      |                                         ^~
a.cc: In constructor 'PMA<T>::PMA()':
a.cc:77:20: error: 'id' was not declared in this scope
   77 |         root->id = id++;
      |                    ^~
a.cc: In function 'int main()':
a.cc:85:19: error: 'uint8_t' was not declared in this scope
   85 |     vector<vector<uint8_t>> T(H);
      |                   ^~~~~~~
a.cc:85:19: note: 'uint8_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:85:19: error: template argument 1 is invalid
a.cc:85:19: error: template argument 2 is invalid
a.cc:85:26: error: template argument 1 is invalid
   85 |     vector<vector<uint8_t>> T(H);
      |                          ^~
a.cc:85:26: error: template argument 2 is invalid
a.cc:88:15: error: 'i' was not declared in this scope
   88 |             T[i][j] = getchar();
      |               ^
a.cc:88:18: error: 'j' was not declared in this scope
   88 |             T[i][j] = getchar();
      |                  ^
a.cc:94:19: error: template argument 2 is invalid
   94 |     vector<vector<uint8_t>> P(R);
      |                   ^~~~~~~
a.cc:94:26: error: template argument 1 is invalid
   94 |     vector<vector<uint8_t>> P(R);
      |                          ^~
a.cc:94:26: error: template argument 2 is invalid
a.cc:97:15: error: 'i' was not declared in this scope
   97 |             P[i][j] = getchar();
      |               ^
a.cc:97:18: error: 'j' was not declared in this scope
   97 |             P[i][j] = getchar();
      |                  ^
a.cc:102:12: error: 'uint32_t' was not declared in this scope
  102 |     vector<uint32_t> M;
      |            ^~~~~~~~
a.cc:102:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:102:20: error: template argument 1 is invalid
  102 |     vector<uint32_t> M;
      |                    ^
a.cc:102:20: error: template argument 2 is invalid
a.cc:103:24: error: template argument 2 is invalid
  103 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                        ^
a.cc:103:32: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  103 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                                ^
      |                                std::begin
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:103:32: error: 'end' was not declared in this scope; did you mean 'std::end'?
  103 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                                ^
      |                                std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:103:37: error: request for member 'push_back' in 'M', which is of non-class type 'int'
  103 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                                     ^~~~~~~~~
a.cc:103:53: error: request for member 'insert' in 'pma_p', which is of non-class type 'int'
  103 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                                                     ^~~~~~
a.cc:104:11: error: request for member 'link_failure' in 'pma_p', which is of non-class type 'int'
  104 |     pma_p.link_failure();
      |           ^~~~~~~~~~~~
a.cc:107:11: error: request for member 'insert' in 'pma_m', which is of non-class type 'int'
  107 |     pma_m.insert(M);
      |           ^~~~~~
a.cc:108:11: error: request for member 'link_failure' in 'pma_m', which is of non-class type 'int'
  108 |     pma_m.link_failure();
      |           ^~~~~~~~~~~~
a.cc:110:19: error: template argument 2 is invalid
  110 |     vector<vector<uint32_t>> T2(W);
      |                   ^~~~~~~~
a.cc:110:27: error: template argument 1 is invalid
  110 |     vector<vector<uint32_t>> T2(W);
      |                           ^~
a.cc:110:27: error: template argument 2 is invalid
a.cc:112:24: error: template argument 2 is invalid
  112 |     for (vector<uint8_t> vec : T) {
      |                        ^
a.cc:112:32: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  112 |     for (vector<uint8_t> vec : T) {
      |                                ^
      |                                std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:112:32: error: 'end' was not declared in this scope; did you mean 'std::end'?
  112 |     for (vector<uint8_t> vec : T) {
      |                                ^
      |                                std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:113:28: error: expected initializer before '*' token
  113 |         PMA<uint8_t>::Node *node = pma_p.root;
      |                            ^
a.cc:114:22: error: expected ';' before 'i'
  114 |         for (uint32_t i = 0; i < vec.size(); i++) {
      |                      ^~
      |                      ;
a.cc:114:30: error: 'i' was not declared in this scope
  114 |         for (uint32_t i = 0; i < vec.size(); i++) {
      |                              ^
a.cc:114:38: error: request for member 'size' in 'vec', which is of non-class type 'int'
  114 |         for (uint32_t i = 0; i < vec.size(); i++) {
      |                                      ^~~~
a.cc:115:13: error: 'node' was not declared in this scope
  115 |             node = pma_p.transition(node, vec[i]);
      |             ^~~~
a.cc:115:26: error: request for member 'transition' in 'pma_p', which is of non-class type 'int'
  115 |             node = pma_p.transition(node, vec[i]);
      |                          ^~~~~~~~~~
a.cc:120:35: error: template argument 1 is invalid
  120 |     vector<pair<uint32_t, uint32_t>> res;
      |                                   ^~
a.cc:120:35: error: template argument 2 is invalid
a.cc:122:29: error: expected initializer before '*' token
  122 |         PMA<uint32_t>::Node *node = pma_m.root;
      |                             ^
a.cc:124:13: error: 'node' was not declared in this scope
  124 |             node = pma_m.transition(node, T2[c][r]);
      |             ^~~~
a.cc:124:26: error: request for member 'transition' in 'pma_m', which is of non-class type 'int'
  124 |             node = pma_m.transition(node, T2[c][r]);
      |                          ^~~~~~~~~~
a.cc:124:45: error: invalid types 'int[int32_t {aka int}]' for array subscript
  124 |             node = pma_m.transition(node, T2[c][r]);
      |                                             ^
a.cc:126:21: error: request for member 'push_back' in 'res', which is of non-class type 'int'
  126 |                 res.push_back(make_pair(r - R + 1, c - C + 1));
      |                     ^~~~~~~~~
a.cc:131:14: error: request for member 'begin' in 'res', which is of non-class type 'int'
  131 |     sort(res.begin(), res.end());
      |              ^~~~~
a.cc:131:27: error: request for member 'end' in 'res', which is of non-class type 'int'
  131 |     sort(res.begin(), res.end());
      |                           ^~~
a.cc:133:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  133 |     for (auto p : res) printf("%d %d\n", p.first, p.second);
      |                   ^~~
      |                   std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:133:19: error: 'end' was not declared in this scope; did you mean 'std::end'?
  133 |     for (auto p : res) printf("%d %d\n", p.first, p.second);
      |                   ^~~
      |                   std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~