【题目链接】

http://poj.org/problem?id=2481

【算法】

树状数组

注意特判两头牛的s,e值相同

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
const int MAXN = 1e5 + ; struct info
{
int id,s,e;
} a[MAXN]; int i,n;
int ans[MAXN]; class BinaryIndexedTree
{
private :
int c[MAXN];
public :
inline void clear()
{
memset(c,,sizeof(c));
}
inline int lowbit(int x)
{
return x & (-x);
}
inline void modify(int pos,int val)
{
int i;
for (i = pos; i < MAXN; i += lowbit(i)) c[i] += val;
}
inline int query(int pos)
{
int i;
int ret = ;
for (i = pos; i; i -= lowbit(i)) ret += c[i];
return ret;
}
inline int query(int l,int r)
{
return query(r) - query(l-);
}
} BIT; inline bool cmp(info a,info b)
{
return a.s != b.s ? a.s < b.s : a.e > b.e;
} int main()
{ while (scanf("%d",&n) && n)
{
BIT.clear();
for (i = ; i <= n; i++)
{
a[i].id = i;
scanf("%d%d",&a[i].s,&a[i].e);
a[i].s++;
a[i].e++;
}
sort(a+,a+n+,cmp);
memset(ans,,sizeof(ans));
for (i = ; i <= n; i++)
{
if (i == )
{
ans[a[i].id] = ;
BIT.modify(a[i].e,);
} else
{
if (a[i].s == a[i-].s && a[i].e == a[i-].e)
ans[a[i].id] = ans[a[i-].id];
else ans[a[i].id] = BIT.query(a[i].e,MAXN-);
BIT.modify(a[i].e,);
}
}
for (i = ; i < n; i++) printf("%d ",ans[i]);
printf("%d\n",ans[n]);
} return ; }

【POJ 2481】 Cows的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. canvas动画简单操作

    canvas动画 小球滚动效果 关键api: window.requestAnimationFrame(draw) 会递归调用draw函数,替代setInterval var x = 20; var ...

  2. nodejs -- crypto MD5签名

    MD5使用方法: const crypto = require('crypto'); var obj = crypto.createHash('md5'); // 可多次调用 update obj.u ...

  3. ubuntu下svn up 出现 Can't convert string from 'UTF-8' to native encoding

    root@ubuntu:/data/www# svn up svn: warning: cannot set LC_CTYPE locale svn: warning: environment var ...

  4. 项目随笔之springmvc中freemark如何获取项目路径

    转载:http://blog.csdn.net/whatlookingfor/article/details/51538995 在SpringMVC框架中使用Freemarker试图时,要获取根路径的 ...

  5. MVC 入口

    1.在 Global.asax public class MvcApplication : System.Web.HttpApplication { protected void Applicatio ...

  6. Python笔记8----DataFrame(二维)

    目录: DataFrame概念 DataFrame创建 基本操作 查看.索引 修改.删除 统计功能 条件筛选 合并 去除空值 4. 一些常用的函数 apply memory_usage pivot_t ...

  7. 算法8-----Different Ways to Add Parentheses(不同括号结果)

    题目: Given a string of numbers and operators, return all possible results from computing all the diff ...

  8. geohash:用字符串实现附近地点搜索

    转自:http://blog.charlee.li/geohash-intro/ geohash:用字符串实现附近地点搜索 上回说到了用经纬度范围实现附近地点搜索.一些小型应用中这样做没问题,但在大型 ...

  9. 使用Word2016直接发布博客

    使用Word2016直接发布博客

  10. windows FTP自动下载脚本

    新建ftp.dat文件,内容如下 open xxx.xxx.xxx.xxxusernamepasswordcd    lcd x:\filesbinaryhashmget *.*bye 新建run.b ...