202006-2 稀疏向量
作者:互联网
注意数据内积可能溢出,需要使用long long
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
int n,a,b;
cin >> n >> a >>b;
unordered_map<int,int> a_map;
int index,value;
for (int i = 0; i < a; i++) {
cin >> index >>value;
a_map.insert(make_pair(index,value));
}
long long muti = 0;
for (int j = 0; j < b; j++) {
cin >> index >>value;
auto it = a_map.find(index);
if(it != a_map.end()){
muti += it->second * value;
}
}
cout << muti <<endl;
return 0;
}
标签:map,index,int,稀疏,value,cin,202006,long,向量 来源: https://blog.csdn.net/JUandjuddd/article/details/118861639