#include<stdio.h>
#include<algorithm>
using namespace std;
int n,t;
long long dap;
struct data{
int x,y;
bool operator<(const data&r)const{
return x<r.x;
}
}a[100010];
struct data2
{
long long val1,val2,val3,val4;
}tree[400010];
void update(int pos,int p)
{
int x=a[pos].y;
while(x<=t)
{
tree[x].val1+=p*a[pos].x*a[pos].y;
tree[x].val2+=p*a[pos].x;
tree[x].val3+=p*a[pos].y;
tree[x].val4+=p;
x+=x&(-x);
}
}
long long query(int x,int a,int b)
{
long long s=0;
while(x)
{
s+=tree[x].val1-b*tree[x].val2-a*tree[x].val3+a*b*tree[x].val4;
x-=x&(-x);
}
return s;
}
int main()
{
int i,maxi=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d",&a[i].x,&a[i].y);
if(maxi<a[i].y) maxi=a[i].y;
}
for(t=1;t<=maxi;t*=2);
sort(a+1,a+n+1);
for(i=1;i<=n;i++)
{
update(i,1);
}
for(i=1;i<=n;i++)
{
update(i,-1);
dap+=query(a[i].y,a[i].x,a[i].y);
dap+=-(query(t,a[i].x,a[i].y)-query(a[i].y,a[i].x,a[i].y));
}
printf("%lld",-dap);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
14364 KB |
Output is correct |
2 |
Correct |
0 ms |
14364 KB |
Output is correct |
3 |
Correct |
0 ms |
14364 KB |
Output is correct |
4 |
Correct |
0 ms |
14364 KB |
Output is correct |
5 |
Correct |
0 ms |
14364 KB |
Output is correct |
6 |
Correct |
0 ms |
14364 KB |
Output is correct |
7 |
Correct |
0 ms |
14364 KB |
Output is correct |
8 |
Correct |
0 ms |
14364 KB |
Output is correct |
9 |
Correct |
0 ms |
14364 KB |
Output is correct |
10 |
Correct |
0 ms |
14364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
14364 KB |
Output is correct |
2 |
Correct |
17 ms |
14364 KB |
Output is correct |
3 |
Correct |
15 ms |
14364 KB |
Output is correct |
4 |
Correct |
10 ms |
14364 KB |
Output is correct |
5 |
Correct |
17 ms |
14364 KB |
Output is correct |
6 |
Correct |
15 ms |
14364 KB |
Output is correct |
7 |
Correct |
15 ms |
14364 KB |
Output is correct |
8 |
Correct |
7 ms |
14364 KB |
Output is correct |
9 |
Correct |
16 ms |
14364 KB |
Output is correct |
10 |
Correct |
10 ms |
14364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
14364 KB |
Output is correct |
2 |
Correct |
20 ms |
14364 KB |
Output is correct |
3 |
Correct |
21 ms |
14364 KB |
Output is correct |
4 |
Correct |
10 ms |
14364 KB |
Output is correct |
5 |
Correct |
18 ms |
14364 KB |
Output is correct |
6 |
Correct |
19 ms |
14364 KB |
Output is correct |
7 |
Correct |
21 ms |
14364 KB |
Output is correct |
8 |
Correct |
16 ms |
14364 KB |
Output is correct |
9 |
Correct |
15 ms |
14364 KB |
Output is correct |
10 |
Correct |
23 ms |
14364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14364 KB |
Output is correct |
2 |
Correct |
46 ms |
14364 KB |
Output is correct |
3 |
Correct |
37 ms |
14364 KB |
Output is correct |
4 |
Correct |
20 ms |
14364 KB |
Output is correct |
5 |
Correct |
26 ms |
14364 KB |
Output is correct |
6 |
Correct |
35 ms |
14364 KB |
Output is correct |
7 |
Correct |
31 ms |
14364 KB |
Output is correct |
8 |
Correct |
38 ms |
14364 KB |
Output is correct |
9 |
Correct |
40 ms |
14364 KB |
Output is correct |
10 |
Correct |
44 ms |
14364 KB |
Output is correct |