Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp> // Common file
- #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
- #include <ext/pb_ds/detail/standard_policies.hpp>
- #define INF 2139062143
- #define EPS 0.0000001
- #define debug(x) cout << #x << " = " << x << endl
- #define fori(i, ini, lim) for(int i= int(ini); i<(int)lim; ++i)
- #define ford(i, ini, lim) for(int i= int(ini); i>=(int)lim; --i)
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef long double ld;
- typedef pair<double, double> ii;
- typedef pair<double, int> id;
- typedef pair<id, ii> event;
- typedef tree<
- pair<double, int>,
- null_type,
- less<pair<double, int> >,
- rb_tree_tag,
- tree_order_statistics_node_update>
- ordered_set;
- int cnt = 0;
- int main(){
- int n;
- while(scanf("%d ", &n) == 1){
- ordered_set active;
- vector<event> v;
- fori(i,0,n){
- double x1, x2, y; scanf("%lf %lf %lf ", &x1,&x2,&y);
- v.push_back(make_pair(ii(x1,0),ii(y,x2)));
- v.push_back(make_pair(ii(x2,2),ii(y,x1)));
- }
- fori(i,0,n){
- double y1, y2, x; scanf("%lf %lf %lf ",&y1,&y2,&x);
- if(y1 > y2) swap(y1, y2);
- v.push_back(make_pair(ii(x,1),ii(y1,y2)));
- }
- sort(v.begin(), v.end());
- ll ans = 0;
- fori(i,0,v.size()){
- event cur = v[i];
- int type = cur.first.second;
- if(type == 0){
- active.insert(id(cur.second.first, cnt++));
- }
- if(type == 2){
- active.erase(active.lower_bound(id(cur.second.first,0)));
- }
- if(type == 1){
- int start = active.order_of_key(id(cur.second.first,INF));
- int end = active.order_of_key(id(cur.second.second+EPS,INF));
- ans += end - start;
- }
- }
- printf("%lld\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement