#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
unordered_map<long, long> mapRow;
unordered_map<long, long> mapCol;
while (n--) {
int type, loc, t;
cin >> type >> loc >> t;
if (type == 1) {
mapRow[t - loc]++;
} else {
mapCol[t - loc]++;
}
}
long res = 0;
for (auto const& entry : mapRow) {
long hasKey = mapCol.count(entry.first);
if (hasKey > 0) {
long colCount = mapCol.at(entry.first);
res += min(colCount, entry.second);
}
}
cout << res << '\n';
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <iostream> #include <unordered_map> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; unordered_map<long, long> mapRow; unordered_map<long, long> mapCol; while (n--) { int type, loc, t; cin >> type >> loc >> t; if (type == 1) { mapRow[t - loc]++; } else { mapCol[t - loc]++; } } long res = 0; for (auto const& entry : mapRow) { long hasKey = mapCol.count(entry.first); if (hasKey > 0) { long colCount = mapCol.at(entry.first); res += min(colCount, entry.second); } } cout << res << '\n'; return 0; } |
English