zoukankan      html  css  js  c++  java
  • 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
    ",CASE,ans);
    66     }
    67     return 0;
    68 }
  • 相关阅读:
    异常作业
    多态作业
    封装和继承作业
    类和对象作业
    多重循环、方法作业
    选择语句+循环语句作业
    数据类型和运算符作业
    初识Java作业
    C 数据结构堆
    C基础 旋转数组查找题目
  • 原文地址:https://www.cnblogs.com/sooflow/p/3263094.html
Copyright © 2011-2022 走看看