hdu 4941

水题竟然没有很快A出来= =

首先对所有点的行,列离散化。

然后维护一个row[i]表示第i行现在所表示的行,同理列也是。那么第i行和第j行交换只要row[i]和row[j]交换一下就可以了。

#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
const int maxn = 100007;

map<pair<int, int>, int> maps;

struct Point {
    int x, y, c;
};
struct Point point[maxn];
int row_num[maxn], col_num[maxn], num_row, num_col, row_turn[maxn], col_turn[maxn];
int n, m, k, q;
int main() {
//    freopen("in.txt", "r", stdin);
    int test_case;
    scanf("%d", &test_case);
    int ncase = 1;
    while (test_case--) {
        scanf("%d%d%d", &n, &m, &k);
        printf("Case #%d:\n", ncase);
        ncase++;
        num_row = num_col = 0;
        maps.clear();
        for (int i = 1; i <= k; i++) {
            scanf("%d%d%d", &point[i].x, &point[i].y, &point[i].c);
            row_num[num_row++] = point[i].x;
            col_num[num_col++] = point[i].y;
        }
        sort(row_num, row_num + num_row);
        sort(col_num, col_num + num_col);
        int row_len = unique(row_num, row_num + num_row) - row_num;
        int col_len = unique(col_num, col_num + num_col) - col_num;
        for (int i = 1; i <= row_len; i++) {
            row_turn[i] = i;
        }
        for (int i = 1; i <= col_len; i++) {
            col_turn[i] = i;
        }
        for (int i = 1; i <= k; i++) {
            int cnt_row, cnt_col;
            cnt_row = lower_bound(row_num, row_num + row_len, point[i].x) - row_num + 1;
            cnt_col = lower_bound(col_num, col_num + col_len, point[i].y) - col_num + 1;
            maps[make_pair(cnt_row, cnt_col)] = point[i].c;
        }
        scanf("%d", &q);
        for (int i = 1; i <= q; i++) {
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            if (a == 3) {
                int pre = b;
                b = lower_bound(row_num, row_num + row_len, b) - row_num;
                if (row_num[b] != pre) {
                    printf("0\n");
                    continue;
                }
                b++;
                b = row_turn[b];
                c = lower_bound(col_num, col_num + col_len, c) - col_num + 1;
                c = col_turn[c];
                if (maps.count(make_pair(b, c))) {
                    printf("%d\n", maps[make_pair(b, c)]);
                }
                else {
                    printf("0\n");
                }
            }
            else if (a == 1) {
                int pre = b;
                b = lower_bound(row_num, row_num + row_len, b) - row_num;
                if (row_num[b] != pre) {
                    continue;
                }
                b++;
                c = lower_bound(row_num, row_num + row_len, c) - row_num + 1;
                swap(row_turn[c], row_turn[b]);
            }
            else if (a == 2) {
                int pre = b;
                b = lower_bound(col_num, col_num + col_len, b) - col_num;
                if (col_num[b] != pre) {
                    continue;
                }
                b++;
                c = lower_bound(col_num, col_num + col_len, c) - col_num + 1;
                swap(col_turn[b], col_turn[c]);
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值