题意:

给你两行数字,n个m个,然后给你k条线直接把两个数连起来,问有多少个交叉的

思路:

假定上一行是起点,下一行是终点。

把路按照起点从大到下排序,

然后可以直接对每条路查询,这条路目前的交叉数,等于sum[终点-1]条路相连,

因为是起点是从大到小,终点是取一个前面点的路,所以肯定相交;

具体处理就是利用树状数组存终点,每次取值,复杂度也低;

然后这个K有问题…

//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1e6+10;
typedef long long LL; struct asd{
int s,t;
};
asd q[N]; bool cmp(asd a,asd b)
{
if(a.s>b.s)
return 1;
if(a.s==b.s)
return a.t>b.t;
return 0;
} LL c[N];
int n,m; int lowbit(int x)
{
return x&(-x);
}
void add(int i,LL v)
{
while(i<=n+7)
{
c[i]+=v;
i+=lowbit(i);
}
}
LL sum(int i)
{
LL ans=0;
while(i>0)
{
ans+=c[i];
i-=lowbit(i);
}
return ans;
}
int main()
{
int T;
int cas=1;
scanf("%d",&T);
while(T--)
{
int num;
LL ans;
scanf("%d%d",&n,&m);
scanf("%d",&num);
for(int i=0;i<num;i++)
scanf("%d%d",&q[i].s,&q[i].t);
sort(q,q+num,cmp);
memset(c,0,sizeof(c));
ans=0;
for(int i=0;i<num;i++)
{
int x=q[i].t;
if(x>1)
ans+=sum(x-1);
add(x,1);
}
printf("Test case %d: %lld\n",cas++,ans);
}
return 0;
}

POJ 3067【树状数组】的更多相关文章

  1. POJ 3321 树状数组(+dfs+重新建树)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27092   Accepted: 8033 Descr ...

  2. POJ 2352Stars 树状数组

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42898   Accepted: 18664 Descripti ...

  3. poj 2299 树状数组求逆序数+离散化

    http://poj.org/problem?id=2299 最初做离散化的时候没太确定可是写完发现对的---由于后缀数组学的时候,,这样的思维习惯了吧 1.初始化as[i]=i:对as数组依照num ...

  4. poj 3928 树状数组

    题目中只n个人,每个人有一个ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判的ID和技能值都在两个选手之间的时候才能进行一场比赛,现在问一共能组织多少场比赛. 由于排完序之后,先插入的一定 ...

  5. POJ 2299 树状数组+离散化求逆序对

    给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...

  6. poj 2299 树状数组求逆序对数+离散化

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 54883   Accepted: 20184 ...

  7. poj 2182 树状数组

    这题对于O(n^2)的算法有很多,我这随便贴一个烂的,跑了375ms. #include<iostream> #include<algorithm> using namespa ...

  8. POJ 2352 树状数组

    学习自:链接以及百度百科 以及:https://www.bilibili.com/video/av18735440?from=search&seid=363548948825132979 理解 ...

  9. POJ 2299树状数组求逆序对

    求逆序对最常用的方法就是树状数组了,确实,树状数组是非常优秀的一种算法.在做POJ2299时,接触到了这个算法,理解起来还是有一定难度的,那么下面我就总结一下思路: 首先:因为题目中a[i]可以到99 ...

  10. MooFest POJ - 1990 (树状数组)

    Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gather ...

随机推荐

  1. LeetCode(155)题解--Min Stack

    https://leetcode.com/problems/min-stack/ 题目: Design a stack that supports push, pop, top, and retrie ...

  2. CI学习相关地址

    1.CI中国:http://codeigniter.org.cn/ 2.CodeIgniter 2.1.3 for SAE:http://codeigniter.org.cn/forums/forum ...

  3. Splits a tensor into sub tensors

    https://www.tensorflow.org/api_docs/python/tf/split # 'value' is a tensor with shape [5, 30] # Split ...

  4. 为编译器的实现者提供一个精确的定义:ANSI C

    编译器的实现 常用C++编译器推荐_w3cschool https://www.w3cschool.cn/cpp/cpp-zxm72ps8.html 常用C++编译器推荐 由 Alma 创建, 最后一 ...

  5. No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386).错误解决方法

    targets ->build setting 下的 Build Active Architecture Only 设置 NO  就可以.

  6. Linux环境下安装MySQL(解压方式)

    1.将安装包放在服务器上:mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz 2.将安装包解压:tar -zxvf mysql-5.6.37-linux-glibc2 ...

  7. SpringSecurityLDap

    ldap,用于用户登录的权限管理, 可参考:http://www.cnblogs.com/icuit/archive/2010/06/10/1755575.html

  8. [CPP] Coding Style

    C++ Coding Style C++很多强大的语言特性导致它的复杂,其复杂性会使得代码更容易出现bug.难于阅读和维护. 由于,本人有一点点代码洁癖,所以依照Google的C++编程规范<G ...

  9. Python升级已经安装的第三方库

    Python升级已经安装的第三方库 主要两步操作,查看需要升级库,升级库.如下: pip list # 列出安装的库 pip list --outdated # 列出有更新的库 pip install ...

  10. html5--5-6 绘制圆/弧

    html5--5-6 绘制圆/弧 学习要点 掌握arc() 方法创建圆弧/曲线(用于创建圆或部分圆) 矩形的绘制方法 rect(x,y,w,h)创建一个矩形 strokeRect(x,y,w,hx,y ...