Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 排序规则究竟应该是什么样的？x升序y升序可以，x降序y降序也可以，x降序y升序就不行

Posted by jiajiawang at 2016-08-08 20:39:09 on Problem 3067
```x升序y升序可以，x降序y降序也可以，y降序x升序就不行，有没有哪位理解的，解释一下？

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int MAX=1000+5;
typedef long long LL;
struct node
{
int x,y;
bool  operator <(const node & a) const
{
return y>a.y||(y==a.y&&x<a.x);
}
};
node a[MAX*MAX];
int bit[MAX];
int N,M;
LL sum(int x)
{
LL s=0;
while(x>0)
{
s=s+bit[x];
x-=(x&(-x));
}
return s;
}
{
while(x<=N)
{
bit[x]++;
x+=(x&(-x));
}
}
int main()
{
ios::sync_with_stdio(false);
int T;
scanf("%d",&T);
for(int tcase=1;tcase<=T;tcase++)
{
int k;
scanf("%d%d%d",&N,&M,&k);
memset(bit,0,sizeof(bit));
for(int i=0;i<k;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a,a+k);
LL ans=0;
for(int i=0;i<k;i++)
{
ans=ans+sum(a[i].x-1);
}
printf("Test case %d: ",tcase);
cout<<ans<<endl;
}
return 0;
}```

Followed by: