/// Radoslaw Mysliwiec 2020
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
#define dd cout << " debug";
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int,int>;
using pll = pair<ll,ll>;
using matrix = vector<vll>;
using ordered_set = tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update>;
int n;
vector<int> a, b;
vector<bool> taken(2000100, 0);
map<int, int> mp, mp2;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
while (n--) {
int x, y, z;
cin >> x >> y >> z;
if (x == 1) a.PB(y - z);
else b.PB(y - z);
}
int res = 0;
for (int i=0; i<a.size(); ++i){
mp[a[i]]++;
}
for (int i=0; i<b.size(); ++i){
mp2[b[i]]++;
}
for (int i=0; i<a.size(); ++i){
if (mp2[a[i]] > 0 && taken[1e6 + a[i]] == false) {
taken[1e6 + a[i]] = true;
res += min(mp[a[i]], mp2[a[i]]);
}
}
cout << res << endl;
}
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | /// Radoslaw Mysliwiec 2020 #pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define F first #define S second #define PB push_back #define ALL(x) (x).begin(),(x).end() #define endl '\n' #define dd cout << " debug"; using ll = long long; using ld = long double; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int,int>; using pll = pair<ll,ll>; using matrix = vector<vll>; using ordered_set = tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update>; int n; vector<int> a, b; vector<bool> taken(2000100, 0); map<int, int> mp, mp2; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; while (n--) { int x, y, z; cin >> x >> y >> z; if (x == 1) a.PB(y - z); else b.PB(y - z); } int res = 0; for (int i=0; i<a.size(); ++i){ mp[a[i]]++; } for (int i=0; i<b.size(); ++i){ mp2[b[i]]++; } for (int i=0; i<a.size(); ++i){ if (mp2[a[i]] > 0 && taken[1e6 + a[i]] == false) { taken[1e6 + a[i]] = true; res += min(mp[a[i]], mp2[a[i]]); } } cout << res << endl; } |
English