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

K2sen

2019-12-22 10:45:21

Solution

## P3613 【深基15.例2】寄包柜 [传送门](https://www.luogu.com.cn/problem/P3613) ### 题目大意 往一个$a[i][j]$ 里边放东西,也可以取走东西,然后查询$a[i][j]$里边是什么东西。 ### 思路: 显然我们可以暴力,但是你开不了那么大的数组。 翻了翻dalao们的题解,为什么要用结构体呢?? 直接$map$他不香吗? 我们用一个$map<int,int> ma[N];$当做暴力的数组来做。 因为$map$如这个STL如果不访问的话是不是占空间的,那么我们就可以~~为所欲为~~A掉这个题了。 code: ```cpp #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; } ```