csp认证 202006-2 稀疏向量

在这里插入图片描述

用map来存储同一位置的u和v即可,key是index。注意可能溢出。

map<int, pair<int, int>> m;

//
// Created by 29273 on 2021-04-07.
//
#include "bits/stdc++.h"

using namespace std;
long long res;

int main() {
    map<int, pair<int, int>> m;
    int n, a, b, x, y;
    cin >> n >> a >> b;
    for (int i = 1; i <= a; ++i) {
        cin >> x >> y;
        m[x].first = y;
    }
    for (int i = 1; i <= b; ++i) {
        cin >> x >> y;
        m[x].second = y;
    }
    for (auto i : m) {
        res += i.second.first * i.second.second;
    }
    cout << res << endl;
    return 0;
}
posted @ 2021-04-07 10:25  沃特艾文儿  阅读(18)  评论(0)    收藏  举报  来源