PURE_LOVE @ 2024-05-06 23:23:22
#include<bits/stdc++.h>
using namespace std;
struct beibao
{
int i;
int j;
beibao() {
i = 0; j = 0;
}
explicit beibao(int x, int y) : i(x), j(y) {}
bool operator<(const beibao& other) const {
if (other.i < i) {
return true;
}
return false;
}
};
int main()
{
int n = 0, t = 0;
cin >> n >> t;
map<beibao, int>arr;
while (t--)
{
int a = 0, b = 0, c = 0, d = 0;
scanf("%d%d%d", &a, &b, &c);
beibao temp;
temp.i = b;
temp.j = c;
if (a == 1)
{
scanf("%d", &d);
auto it = arr.find(temp);
if (it == arr.end())
{
arr[temp] = d;
}
else
{
it->second = d;
}
}
if (a == 2)
{
auto it =arr.find(temp);
printf("%d\n", it->second);
}
}
}
by BJ_BSGF_Lyc @ 2024-05-25 14:00:29
没必要这么复杂,你其实直接一个向量(vector)双重嵌套就好了。
毕竟看到题目中的柜子应该第一印象就是双重数组或双重vector,map等。
vector<vector<int>> a(n+1);
while(q--){
cin>>opt;
if(opt==1){
cin>>i>>j>>k;
if(a[i].size()<j+1) a[i].resize(j+1);
a[i][j]=k;
}
else{
cin>>i>>j;
cout<<a[i][j]<<endl;
}
}
return 0;
这样就可以直接秒杀