题意:给出n头牛的s,e 如果有两头牛,现在si <= sj && ei >= ej

那么称牛i比牛j强壮 然后问每头牛都有几头牛比它强壮

先按照s从小到大排序,然后用e来当做树状数组里面那个a数组,对于每头牛求出前面比他大的e有多少个

还有就是注意有两头牛的s和e相等的情况,就只需要更新值,

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int a[maxn];
int c[maxn];//树状数组
int ans[maxn];// struct node{
int s,e;
int id;
} p[maxn]; int cmp(node n1,node n2){
if(n1.s != n2.s) return n1.s < n2.s;
return n1.e > n2.e;
} int n; int lowbit(int x){ return x & (-x);} int sum(int x){
int ret=;
while( x>){
ret+=c[x];x-=lowbit(x);
}
return ret;
} void add(int x,int d){
while(x < maxn){
c[x]+=d; x+=lowbit(x);
}
} int main(){
while(scanf("%d",&n)!=EOF){
if(n == ) break;
for(int i=;i<=n;i++) scanf("%d %d",&p[i].s,&p[i].e),p[i].id=i;
sort(p+,p+n+,cmp); memset(c,,sizeof(c));
memset(ans,,sizeof(ans)); for(int i=;i<=n;i++){ if(i!= && p[i].s == p[i-].s && p[i].e == p[i-].e) ans[p[i].id] = ans[p[i-].id];
else {
ans[p[i].id] = (i- ) - sum(p[i].e-);
}
add(p[i].e,);
} printf("%d",ans[]);
for(int i=;i<=n;i++) printf(" %d",ans[i]);
printf("\n");
}
return ;
}

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

  1. poj 2481 - Cows(树状数组)

    看的人家的思路,没有理解清楚,,, 结果一直改一直交,,wa了4次才交上,,, 注意: 为了使用树状数组,我们要按照e从大到小排序.但s要从小到大.(我开始的时候错在这里了) 代码如下: #inclu ...

  2. Cows POJ - 2481 (树状数组 + 单点更新 + 区间查询)

    Cows 思路:我们可以按照每个范围的S从小到大排序,相同的S按E从大到小排序,这样的好处是当前范围的S一定大于等于之前范围的S(即当前的范围可能被之前范围的包围),那么我们只需要统计之前的范围E比当 ...

  3. POJ 2481:Cows 树状数组

    Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 14906   Accepted: 4941 Description ...

  4. POJ 2182 Lost Cows (树状数组 && 二分查找)

    题意:给出数n, 代表有多少头牛, 这些牛的编号为1~n, 再给出含有n-1个数的序列, 每个序列的数 ai 代表前面还有多少头比 ai 编号要小的牛, 叫你根据上述信息还原出原始的牛的编号序列 分析 ...

  5. poj2481 Cows 树状数组

    题目链接:http://poj.org/problem?id=2481 解题思路: 这道题对每组数据进行查询,是树状数组的应用.对于二维的树状数组, 首先想到排序.现在对输入的数据按右值从大到小排序, ...

  6. POJ2481:Cows(树状数组)

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

  7. poj 2229 Ultra-QuickSort(树状数组求逆序数)

    题目链接:http://poj.org/problem?id=2299 题目大意:给定n个数,要求这些数构成的逆序对的个数. 可以采用归并排序,也可以使用树状数组 可以把数一个个插入到树状数组中, 每 ...

  8. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  9. poj 2155 Matrix (树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16797   Accepted: 6312 Descripti ...

  10. poj2182Lost Cows——树状数组快速查找

    题目:http://poj.org/problem?id=2182 从后往前确定,自己位置之前没有被确定的且比自己编号小的个数+1即为自己的编号: 利用树状数组快速查找,可另外开一个b数组,角标为编号 ...

随机推荐

  1. 依赖注入Unity框架

    依赖注入和控制反转是对同一件事情的不同描述,从某个方面讲,就是它们描述的角度不同.依赖注入是从应用程序的角度在描述,可以把依赖注入描述完整点:应用程序依赖容器创建并注入它所需要的外部资源:而控制反转是 ...

  2. javascript中DOM基础知识介绍

    1.1.     基本概念 1.1.1.      DOM DOM Document Object Model 文档对象模型 就是把HTML文档模型化,当作对象来处理 DOM提供的一系列属性和方法可以 ...

  3. Function 和 eval 知识点总结

    1 Function 1.1 函数的创建方式 1 函数声明 2 函数表达式 3 new Function // 1 function foo() {} // 2 var foo = function( ...

  4. Python多线程一学就会!

    免费Python课程:阿里云大学——开发者课堂 Python中使用线程有两种方式:函数或者用类来包装线程对象. 函数式:调用thread模块中的start_new_thread()函数来产生新线程.语 ...

  5. Pyhton学习——Day47

    # 转载:http://www.cnblogs.com/yuanchenqi/articles/6357507.html# 外键:一种约束条件,与主键对应# 主表:被绑定的表:字表# 外键约束:# - ...

  6. IOS - 退出程序

    - (void)exitApplication { OAAppDelegate *app = [UIApplication sharedApplication].delegate; UIWindow ...

  7. CodeForces-366C Dima and Salad 对01背包的理解 多个背包问题

    题目链接:https://cn.vjudge.net/problem/CodeForces-366C 题意 给出n个水果和一个常数k,其中每个水果都有两种性质ai, bi(美味度,卡路里量). 要保证 ...

  8. 【Paper Reading】Deep Supervised Hashing for fast Image Retrieval

    what has been done: This paper proposed a novel Deep Supervised Hashing method to learn a compact si ...

  9. laydate 监听日期切换

    ```` //日期范围 laydate.render({ elem: '#Time', range: "至", max: gitData() ,done: function(val ...

  10. php 与 nginx 的两种处理方式

    1.IP:Port 监听方式 php-fpm docker pull PHP:2.4-alpine nginx.conf fastcgi_pass 127.0.0.1:9000; php-fpm 在容 ...