求交点的个数;

容易发现,对于两条航线(xi,yi)和(xj,yj),设xi<xj

只有yi>yj时两条航线存在交点;

于是我们考虑以x为第一关键字减序,y为第二关键字为减序排序;

则对于当前航线(xi,yi),只要找之前所有yj小于yi的个数

所有交点数就是其总和,统计就要用到飘逸的树状数组了~

 var a,c:array[..] of longint;
    x,y:array[..] of longint;
    i,j,n,m,k,t:longint;
    ans:int64; procedure add(p:longint);
  begin
    while p<=m do
    begin
      inc(c[p]);
      p:=p+lowbit(p);
    end;
  end;
function ask(p:longint):longint;
  begin
    ask:=;
    while p<> do
    begin
      ask:=ask+c[p];
      p:=p-lowbit(p);
    end;
  end;
procedure sort(l,r: longint);
  var i,j,h,p: longint;
  begin
    i:=l;
    j:=r;
    h:=x[(l+r) div ];
    p:=y[(l+r) div ];
    repeat
      while (x[i]<h) or (x[i]=h) and (y[i]<p) do inc(i);
      while (h<x[j]) or (x[j]=h) and (p<y[j]) do dec(j);
      if not(i>j) then
      begin
        swap(x[i],x[j]);
        swap(y[i],y[j]);
        inc(i);
        j:=j-;
      end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end; begin
  readln(t);
  for i:= to t do
  begin
    readln(n,m,k);
    for j:= to k do
      readln(x[j],y[j]);
    ans:=;
    sort(,k);
    fillchar(c,sizeof(c),);
    fillchar(a,sizeof(a),);
    inc(a[y[k]]);
    add(y[k]);
    for j:=k- downto do
    begin
      ans:=ans+ask(y[j]-);   //这是唯一要注意的细节,交点一定不能在城市处
      inc(a[y[j]]);
      add(y[j]);
    end;
    writeln('Test case ',i,': ',ans);
  end;
end.

poj3067的更多相关文章

  1. POJ-3067 Japan---树状数组逆序对变形

    题目链接: https://vjudge.net/problem/POJ-3067 题目大意: 日本岛东海岸与西海岸分别有N和M个城市,现在修高速公路连接东西海岸的城市,求交点个数. 解题思路: 记每 ...

  2. poj3067树状数组求逆序数

    Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...

  3. poj3067 Japan 树状数组求逆序对

    题目链接:http://poj.org/problem?id=3067 题目就是让我们求连线后交点的个数 很容易想到将左端点从小到大排序,如果左端点相同则右端点从小到大排序 那么答案即为逆序对的个数 ...

  4. poj3067 二维偏序树状数组

    题解是直接对一维升序排列,然后计算有树状数组中比二维小的点即可 但是对二维降序排列为什么不信呢?? /* */ #include<iostream> #include<cstring ...

  5. poj-3067(树状数组)

    题目链接:传送门 题意:日本有东城m个城市,西城m个城市,东城与西城相互连线架桥,判断这些桥相交的次数. 思路:两个直线相交就是(x1-x2)*(y1-y2)<0,所以,对x,y进行排序,按照x ...

  6. poj3067 Japan(树状数组)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3067">http://poj.org/problem? id=3067 Descri ...

  7. POJ3067(树状数组:统计数字出现个数)

    Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24151   Accepted: 6535 Descriptio ...

  8. POJ3067 Japan

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26270   Accepted: 7132 Description Japa ...

  9. POJ3067:Japan(线段树)

    Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for th ...

随机推荐

  1. eclipse 安装egit 成功后Team中没有显示

    主要是版本不太对. 在http://wiki.eclipse.org/EGit/FAQ#Where_can_I_find_older_releases_of_EGit.3F 中找到对应的版本,设置就O ...

  2. Perl中的特殊内置变量详解

    #!/usr/bin/perl -w @array = qw(a b c d); foreach (@array) { print $_," "; } 例子的作用就是定义一个数组并 ...

  3. Ubuntu下Sublime Text 3无法输入中文的解决方案

    1. 保存下面的代码到文件sublime_imfix.c中: /* * sublime-imfix.c * Use LD_PRELOAD to interpose some function to f ...

  4. MVC学习系列——参考

    C#进阶系列——WebApi接口传参不再困惑:传参详解 http://www.cnblogs.com/landeanfen/p/5337072.html

  5. HDU 3487 Splay

    给定两种操作,一种是把一个数列的某一段切下来插到剩余数列的某一个位置上. 一种是翻转操作,把数列的某一段进行翻转. 都是Splay的基本操作.标准的Rotateto调整出 [a,b]区间.然后对[a, ...

  6. ios9新特性概述

    1.iPad的分屏功能很重要. 开发者对iPad的分屏功能感到兴奋,并认为其对苹果未来非常重要.电子邮件信息应用Hop创始人艾瑞兹·皮洛索夫(Erez Pilosof)认为,如果苹果如传闻中那样决定推 ...

  7. 响应式菜单(bootstrap)

    <nav class="navbar navbar-default" role="navigation"> <div class=" ...

  8. jquery.dragsort实现列表拖曳、排序

    在一次工作中需要将功能模块实现拖曳并且排序,并且将排序结果保存到数据库,用户下次登录后直接读取数据库排序信息进行显示.LZ找了好多插件,最后发现 jquery.dragsort 这款插件是最好使用的, ...

  9. <base target="_blank"/>

    <base target=_blank> 是将基本链接的目标框架都改为新页打开

  10. 为什么样本方差(sample variance)的分母是 n-1?

    为什么样本方差(sample variance)的分母是 n-1? (補充一句哦,題主問的方差 estimator 通常用 moments 方法估計.如果用的是 ML 方法,請不要多想不是你們想的那樣 ...