题意:

n个牛,每个牛对应一个区间,对于每个牛求n个区间有几个包含该牛的区间。

分析:

先 区间右边界从大到小排序,相同时左边界小到大,统计第i头牛即左边界在前i-1头左边界的正序数。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 100010
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int bit[N],tmp[N],n;
struct node{
int s,e,index;
}a[N];
bool cmp(node x,node y){
if(y.e==x.e)
return x.s<y.s;
else
return x.e>y.e;
}
int sum(int x){
int num=;
while(x>){
num+=bit[x];
x-=(x&(-x));
}
return num;
}
void add(int x,int d){
while(x<=N){
bit[x]+=d;
x+=(x&(-x));
}
}
void solve(){
memset(bit,,sizeof(bit));
sort(a,a+n,cmp);
tmp[a[].index]=;
add(a[].s,);
for(int i=;i<n;++i){
if(a[i].s==a[i-].s&&a[i].e==a[i-].e){
tmp[a[i].index]=tmp[a[i-].index];
}
else{
// cout<<i<<" "<<sum(a[i].e)<<endl;
tmp[a[i].index]=sum(a[i].s);
}
add(a[i].s,);
}
for(int i=;i<n;++i){
if(i==n-)
printf("%d\n",tmp[i]);
else
printf("%d ",tmp[i]);
}
}
int main()
{
while(~scanf("%d",&n)){
if(n==)break;
for(int i=;i<n;++i){
scanf("%d%d",&a[i].s,&a[i].e);
a[i].s++;
a[i].e++;
a[i].index=i;
}
solve();
}
return ;
}

POJ 2481-Cows(BIT)的更多相关文章

  1. 2018.07.08 POJ 2481 Cows(线段树)

    Cows Time Limit: 3000MS Memory Limit: 65536K Description Farmer John's cows have discovered that the ...

  2. poj 2481 Cows(数状数组 或 线段树)

    题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [ ...

  3. POJ 2481 Cows(树状数组)

                                                                      Cows Time Limit: 3000MS   Memory L ...

  4. poj 2481 Cows(树状数组)题解

    Description Farmer John's cows have discovered that the clover growing along the ridge of the hill ( ...

  5. 2018.07.03 POJ 3348 Cows(凸包)

    Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in b ...

  6. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  7. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

  8. POJ 3414 Pots(罐子)

    POJ 3414 Pots(罐子) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 You are given two po ...

  9. POJ 1847 Tram (最短路径)

    POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...

  10. 树状数组 POJ 2481 Cows

    题目传送门 #include <cstdio> #include <cstring> #include <algorithm> using namespace st ...

随机推荐

  1. P1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会

    裸的强连通 ; type node=record f,t:longint; end; var n,m,dgr,i,u,v,num,ans:longint; bfsdgr,low,head,f:arra ...

  2. 【学习总结】【多线程】 多线程概要 & GDC & NSOperation

    基本需要知道的 :  进程 :  简单点来说就是,操作系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在受保护的内存空间内 线程 :  一个进程(进程)想执行任务,必须有线程(所以, ...

  3. 通过分析WP的代码来学习PHP。1

    下载了WP的代码,并且应用到了网站上面,现在也在正常的运行中,地址是:www.freealgorithm.tk .具体的申请过程就不赘述了,学习WP的代码. 他的目录结构就不看了,可以下载同名文件我会 ...

  4. Hibernate-Validation的使用

    首先是要加入下面两个包 hibernate-validator-4.1.0.Final.jar validation-api-1.0.0.GA.jar 如果在验证不通过的时候进行了添加.更新或删除操作 ...

  5. 1046-第K回文数

    描述 回文数是这样一个正整数:它从左往右读和从右往左读是一样的.例如1,111,121,505都是回文数.将1到100,000,000内所有回文数按从小到达排序后,第k个回文数是多少呢? 输入 第一行 ...

  6. php获取类的实例变量

    <?php class Page {private $title; //构造函数固定名称为__construct,这样能将php的类构造函数独立于类名,以后修改类名就无需修改构造函数名称 fun ...

  7. Oracle导入(imp )与导出(exp )

    导出exp username/password@orcl file=db.dmp 导入imp username/password@orcl file=h:\db.dmp  full=y 备注:在导入之 ...

  8. mac 用 brew

    mac 下用   brew 安装插件, 有重复的不会再次安装,比xmap模式好

  9. 使用LinkedList实现Stack与Queue

    LinkedList数据结构是一种双向的链式结构,每一个对象除了数据本身外,还有两个引用,分别指向前一个元素和后一个元素. 栈的定义栈(Stack)是限制仅在线性表的一端进行插入和删除运算.(1)通常 ...

  10. win8 hyper-v 禁用不必卸载虚拟机

    转载:http://tylzwp.blogbus.com/logs/232938121.html 禁用hyperv的目的是使用之前在用的VMware的虚拟机,不必重新处理一遍. 具体操作: 1确报之前 ...