HCPC2014校赛训练赛 4 H.Car Race Game (3.16)

H.Car Race Game
Time Limit: 2000 MS Memory Limit: 32768 K
Total Submit: 93 (39 users) Total Accepted: 21 (21 users) Special Judge: No
Description

Bob is a game programming specialist. In his new car race game, there are some racers (n means the amount of racers (1<=n<=100000)). Racers start from someplace (xi means Starting point coordinate), and they possibly have different speed (V means speed). So it possibly takes place to overtake (include starting at the same point). Now he wants to calculate the maximal amount of overtaking.

Input

The first line of the input contains an integer n-determining the number of racers. Next, n lines follow. Each line contains two integers Xi and Vi. (Xi means the ith racer's Starting point coordinate, Vi means the ith racer's speed.0<Xi, Vi<1000000).

Output

For each data set in the input print on a separate line, on the standard output, the integer that represents the maximal amount of overtaking.

Sample Input

2

2 1

2 2

5

2 6

9 4

3 1

4 9

9 1

7

5 5

6 10

5 6

3 10

9 10

9 5

2 2

Sample Output

1

6

7

Hint
Including the same starting points~
Author
BH


#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int x[100010],y;
struct mp
{
    int x,v;
};
bool cmp(mp a,mp b)
{
    if(a.x==b.x) return a.v>b.v;
    return a.x<b.x;
}
int lowbit(int x)
{
    return x&(-x);
}
void add(int u,int v)
{
    while(u<=y)
    {
        x[u]+=v;
        u+=lowbit(u);
    }
}
long long getsum(int u)
{
    long long  s=0;
    while(u>0)
    {
        s+=x[u];
        u-=lowbit(u);
    }
    return s;
}
int main()
{
    int n,i,j;
    while(~scanf("%d",&n))
    {
        mp a[n];long long sum=0; y=0;
        memset(x,0,sizeof(x));
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&a[i].x,&a[i].v);
            if(y<a[i].v) y=a[i].v;
        }
        sort(a,a+n,cmp);
        for(i=0; i<n; i++)
        {
            add(a[i].v,1);
            sum+=(i-getsum(a[i].v)+1);
        }
        printf("%lld\n",sum);
    }
    return 0;
}


     结果:
     
78319 H Accepted G++ 292ms 2144k 975B 2014-03-16 15:18:15
    同题:hrbust OJ  1400 http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1400


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值