http://tjuacm.chaosheng.top/problem.php?id=1261
https://vjudge.net/problem/HDU-4941

直接这么写会报错 [Error] size of array 'forest' is too large

const int INF = 0x3f3f3f3f;
const int N = 2e9;

int n, m, k;

int forest[N][N];
int row[N], col[N];

题目中的N, M 太大 所以不能直接记录
用两个map表示,row[i] = j 表示 i行换到了j行,反之同理 col表示列
另外一个map maze记录<i, j>这个位置的值
每次查询前先将正确的行列在row,col中映射。输出答案就可以

参考 https://blog.csdn.net/weixin_52798818/article/details/116310112

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int n, m, k;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int W;
    cin >> W;
    for(int tt = 1; tt <= W; tt++){
        map<int, map<int, int>> forest;
        map<int, int> xm, ym;

        cin >> n >> m >> k;

        int xa = 0, yb = 0;
        int x, y, c;
        for(int i = 0; i < k; i++){
            cin >> x >> y >> c;
            if(xm[x] == 0){
                xm[x] = ++xa;
            }
            if(ym[y] == 0){
                ym[y] = ++yb;
            }

            forest[xm[x]][ym[y]] = c;
        }

        printf("Case #%d:\n", tt);
        int T, q, a, b, res;
        cin >> T;
        while(T--){
            cin >> q >> a >> b;
            if(q == 1){
                swap(xm[a], xm[b]);
            }else if(q == 2){
                swap(ym[a], ym[b]);
            }else if(q == 3){
                res = forest[xm[a]][ym[b]];
                printf("%d\n", res);
            }
        }
    }
    return 0;
}