poj 3067 Japan

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=1000010+5;
 6 int c[maxn];
 7 int n,m,k;
 8 struct pos
 9 {
10     int e,w;
11     bool operator <(const pos &a) const
12     {
13        if(a.w==w) return e>a.e;
14        return w>a.w;
15     }
16 }p[maxn];
17 int lowbit(int x)
18 {
19     return x&-x;
20 }
21 int sum(int x)
22 {
23     int ret=0;
24     while(x>0)
25     {
26         ret+=c[x];
27         x-=lowbit(x);
28     }
29     return ret;
30 }
31 void add(int x,int inc)
32 {
33     while(x<=n)
34     {
35         c[x]+=inc;
36         x+=lowbit(x);
37     }
38 }
39 int main()
40 {
41     int t;
42     scanf("%d",&t);
43     for(int CASE=1;CASE<=t;CASE++)
44     {
45         scanf("%d%d%d",&n,&m,&k);
46         for(int i=0;i<k;i++)
47             scanf("%d%d",&p[i].e,&p[i].w);
48         sort(p,p+k);
49         __int64 ans=0;
50         memset(c,0,sizeof(c));
51         int tmp=sum(p[0].e);
52         ans+=sum(p[0].e);
53         add(p[0].e,1);
54         for(int i=1;i<k;i++)
55         {
56             if(p[i].e==p[i-1].e)
57                 ans+=tmp;
58             else
59             {
60                 tmp=sum(p[i].e-1);
61                 ans+=tmp;
62             }
63             add(p[i].e,1);
64         }
65         printf("Test case %d: %I64d\n",CASE,ans);
66     }
67     return 0;
68 }

 

转载于:https://www.cnblogs.com/sooflow/p/3263094.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值