AcWing 3288. 稀疏向量
原题链接
简单
作者:
怎么不下雨
,
2025-04-15 19:08:19
· 广东
,
所有人可见
,
阅读 2
#include "bits/stdc++.h"
#define is ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
using namespace std;
int n, r, p;
ll res;
unordered_map<int, int> a, b;
int main() {
is;
cin >> n >> r >> p;
for (int i = 0; i < r; i ++) {
int x, y;
cin >> x >> y;
a[x] = y;
}
for (int i = 0; i < p; i ++) {
int x, y;
cin >> x >> y;
b[x] = y;
}
if (a.size() > b.size()) swap(a, b);
for (auto& [idx, val] : a) {
if (b.count(idx)) res += 1LL * val * b[idx];
}
cout << res;
return 0;
}