POJ 2481-Cows(BIT)
题意:
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)的更多相关文章
- 2018.07.08 POJ 2481 Cows(线段树)
Cows Time Limit: 3000MS Memory Limit: 65536K Description Farmer John's cows have discovered that the ...
- poj 2481 Cows(数状数组 或 线段树)
题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [ ...
- POJ 2481 Cows(树状数组)
Cows Time Limit: 3000MS Memory L ...
- poj 2481 Cows(树状数组)题解
Description Farmer John's cows have discovered that the clover growing along the ridge of the hill ( ...
- 2018.07.03 POJ 3348 Cows(凸包)
Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in b ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- POJ 3281 Dining (网络流)
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...
- POJ 3414 Pots(罐子)
POJ 3414 Pots(罐子) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 You are given two po ...
- POJ 1847 Tram (最短路径)
POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...
- 树状数组 POJ 2481 Cows
题目传送门 #include <cstdio> #include <cstring> #include <algorithm> using namespace st ...
随机推荐
- DB天气 Alpha版使用说明
一 产品介绍 DB天气是一款能够准确预报天气的软件,它的特点在于它的简洁的设计风格,以及贴心的预报方式.是一款非主流的小清新的天气APP. 二 功能介绍 下面介绍一下DB天气的主界面以及天气功能的实现 ...
- 常见架构TLB miss处理方法(转)
转自网站:http://blog.sina.com.cn/s/blog_633f462901018reb.html 0. 综述 总的来说TLB miss处理分为硬件处理和软件处理两种,硬件 ...
- HTML元素大小和位置相对于谁的问题
一.如果元素的position属性值为absolute,那么此时分为两种情况: 1. 父级(包括直接父级和间接父级)元素中没有定义position属性(即默认属性static),那么该元素会参照页面, ...
- 【扩展欧几里得】Bzoj 1407: [Noi2002]Savage
Description Input 第1行为一个整数N(1<=N<=15),即野人的数目.第2行到第N+1每行为三个整数Ci, Pi, Li (1<=Ci,Pi<=100, 0 ...
- Matlab计算矩阵间距离
夜深人静时分,宿舍就我自己,只有蚊子陪伴着我,我慢慢码下这段文字............ 感觉知识结构不完善:上学期看论文,发现类间离散度矩阵和类内离散度矩阵,然后百度,找不到,现在学模式识别,见了, ...
- Eclipse console文本换行
Eclipse换行主要有3个方面 格式化时编辑器文本换行 源代码注释文本换行 Eclipse控制台console显示文本换行 1和2参考 http://hi.baidu.com/ae6623/item ...
- Flume学习——BasicChannelSemantics
public class MemoryChannel extends BasicChannelSemantics public abstract class BasicChannelSemantics ...
- spark storage之SparkEnv
此文旨在对spark storage模块进行分析,整理自己所看所得,等以后再整理. ok,首先看看SparkContext中sparkEnv相关代码: private[spark] def creat ...
- CentOS 5: Make Command not Found
在centos 5下安装软件遇到的问题,google了一圈,是因为系统没有安装编译器,那安装就是了,嘿嘿. 解决办法,在SSH下输入下面的命令 yum -y install gcc automake ...
- POJ2527+多项式除法
模拟一遍即可. 注意一些特殊情况,见代码. #include<stdio.h> #include<stdlib.h> #include<math.h> #inclu ...