题解 P3613 【【深基15.例2】寄包柜】

· · 题解

P3613 【深基15.例2】寄包柜

传送门

题目大意

往一个a[i][j] 里边放东西,也可以取走东西,然后查询a[i][j]里边是什么东西。

思路:

显然我们可以暴力,但是你开不了那么大的数组。

翻了翻dalao们的题解,为什么要用结构体呢??

直接map他不香吗?

我们用一个map<int,int> ma[N];当做暴力的数组来做。

因为map如这个STL如果不访问的话是不是占空间的,那么我们就可以为所欲为A掉这个题了。

code:

#include <bits/stdc++.h>

#define N 100010
#define M 1010

using namespace std;
int n, q;
map<int, int>ma[N];

int read() {
    int s = 0, f = 0; char ch = getchar();
    while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
    return f ? -s : s;
}

int main() {
    n = read(), q = read();
    for (int i = 1, opt, x, y, sy; i <= q; i++) {
        opt = read(), x = read(), y = read();
        if (opt == 1) {
            sy = read();
            ma[x][y] = sy;
        } else printf("%d\n", ma[x][y]);
    }
    return 0;
}