#include "supermerge.h"

#include <iostream>

int main()
{
    int n, valmax, q;
    std::cin >> n >> valmax >> q;

    init(n, valmax);

    while (q--) {
        int type;
        std::cin >> type;
        if (type == 0) {
            int x, val;
            std::cin >> x >> val;
            std::cout << flip(x, val) << '\n';
        } else {
            int st1, dr1, st2, dr2;
            std::cin >> st1 >> dr1 >> st2 >> dr2;
            std::cout << supermerge(st1, dr1, st2, dr2) << '\n';
        }
    }

    return 0;
}
