上述题目中可以将map当作二维数组使用,而且这样对空间的浪费还比较小,虽然时间上会稍大一点
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
map<int,int> m[N];
int n,q;
int main()
{
cin>>n>>q;
while(q--)
{
int t,i,j,k;
cin>>t;
if(t==1)
{
cin>>i>>j>>k;
if(k==0)
m[i][j]=k;
else
m[i][j]+=k;
}
else
{
cin>>i>>j;
cout<<m[i][j]<<endl;
}
}
}