AcWing 3288. 稀疏向量
原题链接
简单
作者:
王欢祥
,
2024-12-03 10:27:08
,
所有人可见
,
阅读 1
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
#define ll long long
ll n, a, b;
map<ll, ll> u, v;
long long int sum = 0;
int main() {
scanf("%lld%lld%lld", &n, &a, &b);
for (int i = 1; i <= a; i++) {
ll index, value;
scanf("%lld%lld", &index, &value);
u[index] = value;
}
for (int i = 1; i <= b; i++) {
ll index, value;
scanf("%lld%lld", &index, &value);
v[index] = value;
}
map<ll, ll>::iterator u1, v1;
u1 = u.begin();
v1 = v.begin();
while (u1 != u.end() && v1 != v.end()) {
ll x1 = u1->first, y1 = u1->second, x2 = v1->first, y2 = v1->second;
if (x1 < x2) {
u1++;
continue;
} else if (x1 > x2) {
v1++;
continue;
} else {
sum += y1 * y2;
u1++;
v1++;
}
}
cout << sum << endl;
return 0;
}