-
-
Save enzerr/cddd781152da5ea3cae4a41f33403381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
#define tii tuple<int, int, int, int, int> | |
#define all(x) x.begin(), x.end() | |
#define pb push_back | |
const int maxn = 2e5+5, INF = 0x3f3f3f3f; | |
int calc[maxn], bit[maxn]; | |
vector<tii> pontos; | |
vector<int> comp; | |
int pos(int x){ | |
int l=0, r= comp.size()-1; | |
while(l<=r){ | |
int m = (l+r)>>1; | |
if(comp[m]<x) l=m+1; | |
else r = m-1; | |
} | |
return l+1; | |
} | |
void upd(int x){ | |
for(; x < maxn; x+=x&-x) bit[x]++; | |
} | |
int sum(int x){ | |
int rt = 0; | |
for(; x > 0; x-=x&-x) rt+=bit[x]; | |
return rt; | |
} | |
int32_t main(){ | |
ios::sync_with_stdio(false); cin.tie(0); | |
memset(calc, INF, sizeof calc); | |
int n; cin >> n; | |
for(int i = 0; i < n; i++){ | |
int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; | |
pontos.pb({x1, y2, x1, y1, i}); // inferior/superior esquerdo | |
pontos.pb({x2, y1, x2, y2, i}); // superior/inferior direito | |
comp.pb(y1), comp.pb(y2); | |
} | |
sort(all(pontos)); | |
sort(all(comp)); | |
comp.erase(unique(all(comp)), comp.end()); | |
int ans = 0; | |
for(auto[xp, yp, xm, ym, i] : pontos){ | |
int val = sum(pos(yp)) - sum(pos(ym)); | |
if(calc[i]==INF) calc[i] = val; | |
else{ | |
if(calc[i]+val==0) ans++; | |
upd(pos(yp)); | |
} | |
} | |
cout << ans << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment