【POJ 2481】 Cows
【题目链接】
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的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- Several Ideas on Perl List Context
According to Beginning Perl Book published by Tsinghua Pub., the list context appears when you are t ...
- Java基础6一面向对象
面向对象的编程思想:是以事物的整体的为基本单位,从事物的属性和行为两个方面进行描述. 特点: Java来源于生活服务于生活 用面向对象的思想能够接近正常的思维方式. 面向对象语言中有设计模式一说. 在 ...
- 第八课: - 从Microsoft SQL数据库读取
第 8 课 如何从Microsoft SQL数据库中提取数据 In [1]: # Import libraries import pandas as pd import sys from sqlalc ...
- JavaScript与jquery的对比
javascript jQuery 入口函数 只能有一个,如果有多个,后面的会覆盖前面 可以有多个,并且不会发生覆盖的情况 代码容错性 代码容错性差,代码出现错误,会影响到后面代码的运行. 代码容 ...
- VM虚拟机NAT模式主机与虚拟机ping不通解决方案
VM虚拟机与真机通信三种模式, 桥接模式,NAT 模式 ,HOST-ONLY 模式. NAT模式 使用虚拟机的一个虚拟网卡做NAT网关,在nat网关上配dhcp ,或者直接用静态地址.就相当于形成了一 ...
- DB2 char长度问题
问题:发现用char转换了后的值长度都变为了11,更长的变为了254
- VHDL_LIB之DFF
1 D-Flip-Flop with async reset or set library IEEE; use ieee.std_logic_1164.all; entity FFD is gener ...
- 【数据分析学习】Pandas思维导图
点我查看原版
- Day 13迭代器生成器
迭代器 1.迭代器就是迭代的工具,迭代也可以说成是重复,并且每一次重复都是基于上一次的结果而来的,在python中一切皆对象. 2.可迭代对象:只要拥有__iter__方法的对象都是可迭代对象. 3. ...
- Linux分布式测试
在使用Jmeter进行性能测试时,如果并发数比较大(比如最近项目需要支持1000并发),单台电脑的配置(CPU和内存)可能无法支持,这时可以使用Jmeter提供的分布式测试的功能. 执行机和调度机做好 ...