Language: C++

#include <iostream>
#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:13:5: error: 'uint32_t' does not name a type
   13 |     uint32_t id = 0;
      |     ^~~~~~~~
a.cc:7:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    6 | #include <algorithm>
  +++ |+#include <cstdint>
    7 | 
a.cc:17:9: error: 'uint32_t' does not name a type
   17 |         uint32_t id;
      |         ^~~~~~~~
a.cc:17: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:33:41: error: 'id' was not declared in this scope
   33 |                 node->children[v]->id = id++;
      |                                         ^~
a.cc: In constructor 'PMA<T>::PMA()':
a.cc:76:20: error: 'id' was not declared in this scope
   76 |         root->id = id++;
      |                    ^~
a.cc: In function 'int main()':
a.cc:84:19: error: 'uint8_t' was not declared in this scope
   84 |     vector<vector<uint8_t>> T(H);
      |                   ^~~~~~~
a.cc:84:19: note: 'uint8_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:84:19: error: template argument 1 is invalid
a.cc:84:19: error: template argument 2 is invalid
a.cc:84:26: error: template argument 1 is invalid
   84 |     vector<vector<uint8_t>> T(H);
      |                          ^~
a.cc:84:26: error: template argument 2 is invalid
a.cc:87:15: error: 'i' was not declared in this scope
   87 |             T[i][j] = getchar();
      |               ^
a.cc:87:18: error: 'j' was not declared in this scope
   87 |             T[i][j] = getchar();
      |                  ^
a.cc:93:19: error: template argument 2 is invalid
   93 |     vector<vector<uint8_t>> P(R);
      |                   ^~~~~~~
a.cc:93:26: error: template argument 1 is invalid
   93 |     vector<vector<uint8_t>> P(R);
      |                          ^~
a.cc:93:26: error: template argument 2 is invalid
a.cc:96:15: error: 'i' was not declared in this scope
   96 |             P[i][j] = getchar();
      |               ^
a.cc:96:18: error: 'j' was not declared in this scope
   96 |             P[i][j] = getchar();
      |                  ^
a.cc:101:12: error: 'uint32_t' was not declared in this scope
  101 |     vector<uint32_t> M;
      |            ^~~~~~~~
a.cc:101:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:101:20: error: template argument 1 is invalid
  101 |     vector<uint32_t> M;
      |                    ^
a.cc:101:20: error: template argument 2 is invalid
a.cc:102:24: error: template argument 2 is invalid
  102 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                        ^
a.cc:102:32: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  102 |     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:102:32: error: 'end' was not declared in this scope; did you mean 'std::end'?
  102 |     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:102:37: error: request for member 'push_back' in 'M', which is of non-class type 'int'
  102 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                                     ^~~~~~~~~
a.cc:102:53: error: request for member 'insert' in 'pma_p', which is of non-class type 'int'
  102 |     for (vector<uint8_t> vec : P) M.push_back(pma_p.insert(vec));
      |                                                     ^~~~~~
a.cc:103:11: error: request for member 'link_failure' in 'pma_p', which is of non-class type 'int'
  103 |     pma_p.link_failure();
      |           ^~~~~~~~~~~~
a.cc:106:11: error: request for member 'insert' in 'pma_m', which is of non-class type 'int'
  106 |     pma_m.insert(M);
      |           ^~~~~~
a.cc:107:11: error: request for member 'link_failure' in 'pma_m', which is of non-class type 'int'
  107 |     pma_m.link_failure();
      |           ^~~~~~~~~~~~
a.cc:109:19: error: template argument 2 is invalid
  109 |     vector<vector<uint32_t>> T2(W);
      |                   ^~~~~~~~
a.cc:109:27: error: template argument 1 is invalid
  109 |     vector<vector<uint32_t>> T2(W);
      |                           ^~
a.cc:109:27: error: template argument 2 is invalid
a.cc:111:24: error: template argument 2 is invalid
  111 |     for (vector<uint8_t> vec : T) {
      |                        ^
a.cc:111:32: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  111 |     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:111:32: error: 'end' was not declared in this scope; did you mean 'std::end'?
  111 |     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:112:28: error: expected initializer before '*' token
  112 |         PMA<uint8_t>::Node *node = pma_p.root;
      |                            ^
a.cc:113:22: error: expected ';' before 'i'
  113 |         for (uint32_t i = 0; i < vec.size(); i++) {
      |                      ^~
      |                      ;
a.cc:113:30: error: 'i' was not declared in this scope
  113 |         for (uint32_t i = 0; i < vec.size(); i++) {
      |                              ^
a.cc:113:38: error: request for member 'size' in 'vec', which is of non-class type 'int'
  113 |         for (uint32_t i = 0; i < vec.size(); i++) {
      |                                      ^~~~
a.cc:114:13: error: 'node' was not declared in this scope
  114 |             node = pma_p.transition(node, vec[i]);
      |             ^~~~
a.cc:114:26: error: request for member 'transition' in 'pma_p', which is of non-class type 'int'
  114 |             node = pma_p.transition(node, vec[i]);
      |                          ^~~~~~~~~~
a.cc:119:35: error: template argument 1 is invalid
  119 |     vector<pair<uint32_t, uint32_t>> res;
      |                                   ^~
a.cc:119:35: error: template argument 2 is invalid
a.cc:121:29: error: expected initializer before '*' token
  121 |         PMA<uint32_t>::Node *node = pma_m.root;
      |                             ^
a.cc:123:13: error: 'node' was not declared in this scope
  123 |             node = pma_m.transition(node, T2[c][r]);
      |             ^~~~
a.cc:123:26: error: request for member 'transition' in 'pma_m', which is of non-class type 'int'
  123 |             node = pma_m.transition(node, T2[c][r]);
      |                          ^~~~~~~~~~
a.cc:123:45: error: invalid types 'int[int32_t {aka int}]' for array subscript
  123 |             node = pma_m.transition(node, T2[c][r]);
      |                                             ^
a.cc:125:21: error: request for member 'push_back' in 'res', which is of non-class type 'int'
  125 |                 res.push_back(make_pair(r - R + 1, c - C + 1));
      |                     ^~~~~~~~~
a.cc:130:14: error: request for member 'begin' in 'res', which is of non-class type 'int'
  130 |     sort(res.begin(), res.end());
      |              ^~~~~
a.cc:130:27: error: request for member 'end' in 'res', which is of non-class type 'int'
  130 |     sort(res.begin(), res.end());
      |                           ^~~
a.cc:132:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  132 |     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:132:19: error: 'end' was not declared in this scope; did you mean 'std::end'?
  132 |     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;
      |                                     ^~~