Title Description
There are n-$ $ points in the plane, the coordinates of the points $ I $ is $ X_i, Y_i $. For which a non-empty set of points $ S $, defined $ f (S) $ as a minimum rectangle, satisfy:
$ \ bullet $ cover $ S $ all points (at the boundary can be considered covered); $
\ bullet $ sides parallel to the coordinate axes.
All the different requirements of $ f (S) $ and the area of $ 7 $ 10 ^ 9 + modulo results. Two rectangles are considered different, if and only if they have different vertex coordinates.
Input Format
Read data from files $ rectangle.in $ in.
A first line integer $ n $.
Next $ $ n-lines of two integers $ X_i, Y_i $.
Output Format
Output to a file in $ rectangle.out $.
A row of integer answer.
Sample
Sample input:
4
1 2
3 1
4 4
5 1
Sample output:
45
Data range and tips
Sample explained:
$ $ 8 has a rectangular area greater than $ 0 $ different, the following are the coordinates of the upper right corner and lower left corner thereof:
$ (1,1), (3,2); (1,1), (4,4); (1 , 1), (5,2); (1,1), (5,4) $
$ (1,2), (4,4); (3,1), (4,4); (3, 1), (5,4); (4,1), (5,4) $
data range:
For all data, meet $ 2 \ leqslant n \ leqslant 10 ^ 4,1 \ leqslant X_i, Y_i \ leqslant 2500 $, no duplicate points.
$ \ bullet Subtask1 (13 \% ) $, $ n \ leqslant 18 $.
$ \ bullet Subtask2 (9 \% ) $, $ n \ leqslant 50 $.
$ \ bullet Subtask3 (25 \% ) $, $ n \ leqslant 300 $.
$ \ bullet Subtask4 (21 \% ) $, $ n \ leqslant 2500, X_i \ neq X_j, Y_i \ neq Y_j $.
$ \ bullet Subtask5 (19 \% ) $, $ n \ leqslant 2500 $.
$ \ bullet Subtask6 (13 \% ) $, no special constraints.
answer
Consider first $ 21 \% $ of $ X_i \ neq X_j, Y_i \ neq Y_j $ circumstances of.
We about $ n ^ 2 $ enumeration boundary, then the point is provided on the boundary $ (L, y_1) $ and $ (R, y_2) $.
Then only located $ (L, R) $ and the ordinate $> \ max (y_1, y_2) $ and $ <\ min (y_1, y_2) $ points to contribute, we can consider Fenwick tree, stored $ \ sum y $ can (length varies, but the height unchanged).
Now consider the general case, there may be a lot of points on each $ L $ and $ R $, we turn to enumerate count.
But the situation may occur in the following figure:
Obviously, we contributed $ 1,3 points in the statistical answer and point $ $ $ 2,3 when matrix operators will be heavy purple, do not worry, we only need to coordinate statistics at the most by vertical enough.
Code for a little cumbersome.
Time complexity: $ \ Theta (nm \ log m) $.
Expectations score: $ 100 $ points.
Actual score: $ 100 $ points.
Code time
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int n;
int Map[2501][2501];
int tr[2][2501][2501];
bool vis[2501][2501];
long long ans;
int lowbit(int x){return x&-x;}
void add(int id,int k,int x,int w)
{
for(int i=x;i<=2500;i+=lowbit(i))
tr[id][k][i]+=w;
}
int ask(int id,int k,int x)
{
int res=0;
for(int i=x;i;i-=lowbit(i))res+=tr[id][k][i];
return res;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
Map[x][++Map[x][0]]=y;
}
for(int i=1;i<=2500;i++)
{
sort(Map[i]+1,Map[i]+Map[i][0]+1);
Map[i][Map[i][0]+1]=2501;
}
for(int i=1;i<=2500;i++)
{
if(!Map[i][0])continue;
for(int j=1;j<=Map[i][0];j++)
if(!vis[i][Map[i][j]])
{
vis[i][Map[i][j]]=1;
add(1,i,Map[i][j],1);
add(0,i,Map[i][j],Map[i][j]);
}
for(int j=i-1;j;j--)
{
if(!Map[j][0])continue;
int l1=1,l2=1;
for(int k=1;k<=Map[j][0];k++)
if(!vis[i][Map[j][k]])
{
vis[i][Map[j][k]]=1;
add(1,i,Map[j][k],1);
add(0,i,Map[j][k],Map[j][k]);
}
int wzc=max(Map[i][1],Map[j][1]);
while(Map[i][l1+1]<=wzc)l1++;
while(Map[j][l2+1]<=wzc)l2++;
while(l1<=Map[i][0]&&l2<=Map[j][0])
{
int flag=min(Map[i][l1+1],Map[j][l2+1]);
ans=(ans+1LL*(i-j)*((ask(0,i,flag-1)-ask(0,i,wzc-1))*ask(1,i,min(Map[i][l1],Map[j][l2]))-((ask(1,i,flag-1)-ask(1,i,wzc-1))*ask(0,i,min(Map[i][l1],Map[j][l2])))))%mod;
wzc=flag;
if(Map[i][l1+1]<=wzc)l1++;
if(Map[j][l2+1]<=wzc)l2++;
}
}
}
printf("%lld\n",ans);
return 0;
}
rp++