#include <bits/stdc++.h> #define FOR(i, a, b) for(int i = a; i<b; ++i) #define FR(a, b) for(int i = a; i>=b;--i) #define _fastio cin.tie(0); ios_base::sync_with_stdio(0) #define pb push_back #define mp make_pair #define INF 1e13 using namespace std; typedef long long ll; typedef double db; typedef unsigned long long ull; typedef pair<int, int> iPair; const int MAX = 5e5 + 2; const int M = 1e9 +7; int n, res; map<int, int> a, b; int main() { _fastio; cin>>n; FOR(i, 0, n) { int x, y, z; cin>>x>>y>>z; if(x == 1) a[y-z]++; else b[y-z]++; } for(auto x : a) res += min(x.second, b[x.first]); cout<<res<<"\n"; }
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 33 34 35 36 37 38 | #include <bits/stdc++.h> #define FOR(i, a, b) for(int i = a; i<b; ++i) #define FR(a, b) for(int i = a; i>=b;--i) #define _fastio cin.tie(0); ios_base::sync_with_stdio(0) #define pb push_back #define mp make_pair #define INF 1e13 using namespace std; typedef long long ll; typedef double db; typedef unsigned long long ull; typedef pair<int, int> iPair; const int MAX = 5e5 + 2; const int M = 1e9 +7; int n, res; map<int, int> a, b; int main() { _fastio; cin>>n; FOR(i, 0, n) { int x, y, z; cin>>x>>y>>z; if(x == 1) a[y-z]++; else b[y-z]++; } for(auto x : a) res += min(x.second, b[x.first]); cout<<res<<"\n"; } |