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 ...
随机推荐
- Multi-Device Hybrid Apps (Preview)
Today, we released a preview of Visual Studio tooling support for Apache Cordova http://msdn.microso ...
- 实时数据处理环境搭建flume+kafka+storm:0.环境依赖
storm需要java和Python 部署依赖环境 --- 要求Java 6+ .Python 2.6.6+ java,python安装配置完成
- SQL Server 和 Oracle 以及 MySQL 有哪些区别?
SQL,在这里我理解成SQL Server.三者是目前市场占有率最高(依安装量而非收入)的关系数据库,而且很有代表性.排行第四的DB2(属IBM公司),与Oracle的定位和架构非常相似,就不赘述了. ...
- 利用手上的UI资源(附免费UI工具包)
http://www.uisdc.com/how-to-use-ui-kits# 大家都知道,UI工具包里有很多好看的资源:比如按钮.滑块.面包屑.播放器.表单,甚至是一个"赞!" ...
- 多线程 (三)iOS中的锁
锁的类别:互斥锁,递归锁,条件锁,自旋锁等 锁的实现方式:NSLock,NSRecursiveLock, NSConditionLock,@synchronized,GCD的信号量等 下面说一下常用的 ...
- codeforces #313 div1 C
同BZOJ 3782 上学路线 QAQ 还比那个简单一点 把坐标(1,1)-(n,m)平移成(0,0)-(n-1,m-1) 设dp[i]表示从(1,1)出发第一次经过障碍且到达第i个障碍的方案数 首先 ...
- 李洪强iOS开发本人集成环信的经验总结_09_处理好友请求
李洪强iOS开发本人集成环信的经验总结_09_处理好友请求 实现这种效果: 01 - 遵守处理好友请求的代理协议 02 - 设置代理 03 - 实现代理方法 04 - 实现代理中用到的方法
- 李洪强iOS开发之静态库
iOS开发拓展篇—静态库 一.简单介绍 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.库的分类 根据源代码的公开情况,库可以分为2种类型 (1)开源库 公开源代码,能看到具体实现 ...
- SaaS系列介绍之六: SaaS模式分析(上)
1 引言 如果我们想要更多的玫瑰花,就必须种植更多的玫瑰树. ________姚群<成功激励格言精选> SaaS模式是个新兴的话题,有 ...
- [Unity菜鸟] 术语
HUD Mozilla Mozilla基金会,简称Mozilla(缩写MF或MoFo),是为支持和领导开源的Mozilla项目而设立的一个非营利组织. 称作Mozilla公司的子公司,雇佣了一些Mo ...