【题目链接】

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. C++批量加载动态库函数方法

    1.枚举定义enum  {    // 0 - GigE DLL (implicitly called)    Func_isVersionCompliantDLL,    Func_isDriver ...

  2. JavaScript操作HTML&CSS简单入门

    - Java攻城狮学习路线 - 一. JavaScript基础 输出 使用 window.alert() 弹出警告框. 使用 document.write() 方法将内容写到 HTML 文档中. 使用 ...

  3. JavaScript获取非行间样式

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  4. javascript 的逻辑中断(短路操作)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. MongoDB 博客截图之一

    来源:十天掌握MongoDB之三:学会Find - 学吧网 - 专注于PHP资源分享

  6. smarty 3 + codeigniter 2 + hmvc

    参考资料 https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/src/fecd39ccdf56?at=defau ...

  7. java必备技能

    Android应用程序开发是以Java语言为基础的,所以需要有扎实的Java基础知识.首先熟悉java基本语法,然后熟悉设计模式等. a) Java基础语法:看下面的<Java知识点列表> ...

  8. Editing a Book 搜索 + meet in the middle

    我们可以发现最多只会进行5次操作. 由此我们从双向跑dfs,用一个unordered_map来保存状态,枚举一下两边的深度即可. 如果4次仍然不可行,则只有可能是5次.所以正反最多只需要搜2层 cod ...

  9. 前端html之------>Table实现表头固定

    文章来源于:https://www.cnblogs.com/dacuotecuo/p/3657779.html,请尊重原创,转载请注明出处. 说明:这里主要实现了表头的固定和上下滚动的滑动实现:时间的 ...

  10. jmeter的组成

    1.jmeter的组成 线程组:控制多线程并发 断言:预期是否与实际结果一致,性能测试经验不建议做断言 定时器:自已操作线程停顿的时间 监听器:调试自已的脚本和对系统的监控 配置原件:配置的插件 后置 ...