题意:给定一些线 判断 一共有多少矩形
和之前那题cf u型 有点类似 枚举 与x轴平行的边 然后扫出与y轴平行的边(与这两条枚举边都相交) 把该边x放入树状数组 求贡献即可 该贡献为 枚举的两条边为矩形的上下底的矩形个数
#include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>=(b);--i) #define RI(n) scanf("%d",&(n)) #define RII(n,m) scanf("%d%d",&n,&m) #define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k) #define RS(s) scanf("%s",s) #define ll long long #define see(x) (cerr<<(#x)<<'='<<(x)<<endl) #define pb push_back #define inf 0x3f3f3f3f #define pb push_back #define CLR(A,v) memset(A,v,sizeof A) #define lson l,m,pos<<1 #define rson m+1,r,pos<<1|1 typedef pair<int,int>pii; ////////////////////////////////// const int N=1e5+5; const int off=5002; struct X { int x,y1,y2; }; struct Y { int y,x1,x2; }; bool cmpx(X a,X b){return a.y2<b.y2;} bool cmpy(Y a,Y b){return a.y<b.y;} int t[N]; void up(int x,int v){for(;x<=N;x+=x&-x)t[x]+=v; } int qsum(int x){int ans=0;for(;x;x-=x&-x)ans+=t[x];return ans;} int n,x1,x2,y1,y2;vector<X>x;vector<Y>y; int main() { RI(n); rep(i,1,n) { RII(x1,y1);RII(x2,y2); if(x1==x2) { if(y1>y2)swap(y1,y2);x.pb(X{x1+off,y1+off,y2+off}); } else { if(x1>x2)swap(x1,x2);y.pb(Y{y1+off,x1+off,x2+off}); } } sort(x.begin(),x.end(),cmpx); sort(y.begin(),y.end(),cmpy); ll ans=0; for(int i=0;i<y.size();++i) { int k=x.size()-1;CLR(t,0); for(int j=y.size()-1;y[j].y>y[i].y;--j) { while(k>=0&&x[k].y2>=y[j].y) { if(x[k].y1<=y[i].y) up(x[k].x,1); k--; } int l=max(y[i].x1,y[j].x1),r=min(y[i].x2,y[j].x2); if(l>=r)continue; int ret=qsum(r)-qsum(l-1); ans+=1ll*(ret-1)*ret/2; } } cout<<ans; return 0; }