题解:B4030 [语言月赛 202409] 距离
题目传送门
\texttt{Description}
给定
\texttt{Solution}
可以用 STL 中的 map 来做。把每次输入的两个数当作一个 pair 把对应加减的数值存进去。
\texttt{Code}
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> pii;
map<pii, int> mp;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m, maxx = -1e18;
cin >> n >> m;
while (m--) {
int op, a, b, c;
cin >> op >> a >> b >> c;
pii pi = {a, b};
if (op == 1) mp[pi] += c;
else mp[pi] -= c;
maxx = -1e18;
for (auto p : mp) maxx = max(maxx, p.second);
cout << maxx << "\n";
}
return 0;
}
注意,auto 只有 C++14 及以上才能用。
完结。