【题目链接】

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

【算法】

树状数组 + 二分

【代码】

#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;
#define MAXN 8010 int i,n;
int a[MAXN],ans[MAXN],c[MAXN]; inline int lowbit(int x)
{
return x & (-x);
}
inline void modify(int pos,int val)
{
int i;
for (i = pos; i <= n; 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 get(int k)
{
int l = ,r = n,mid;
int ret;
while (l <= r)
{
mid = (l + r) >> ;
if (query(mid) >= k)
{
ret = mid;
r = mid - ;
} else l = mid + ;
}
return ret;
} int main()
{ scanf("%d",&n);
for (i = ; i <= n; i++) scanf("%d",&a[i]);
for (i = ; i <= n; i++) c[i] = lowbit(i);
for (i = n; i >= ; i--)
{
ans[i] = get(a[i]+);
modify(ans[i],-);
}
for (i = ; i <= n; i++) printf("%d\n",ans[i]); return ; }

【POJ 2182】Lost Cows的更多相关文章

  1. 【POJ 2186】Popular Cows

    http://poj.org/problem?id=2186 tarjan求强连通分量. 因为SD省选用WinXP+Cena评测而且不开栈,所以dfs只好写手动栈了. 写手动栈时思路清晰一点应该是不会 ...

  2. 【POJ - 2456】Aggressive cows(二分)

    Aggressive cows 直接上中文了 Descriptions 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 项目中遇到的所有ECharts图表集合

    全放在了ECharts官网示例里面以后会一直往里面添加: https://gallery.echartsjs.com/explore.html?u=bd-2133619855&type=wor ...

  2. 自定义SearchView实现即时查询

    1.效果图,输入关键字时会根据关键字改变而更新数据. 2.其布局文件和2个小图标del.png和searchview.png,布局文件如下:高度已固定为46dp. <?xml version=& ...

  3. 使用Word 2010群发邮件

    1.建立数据库,这里我使用了excel 字段:电子邮件地址,名字 填写需要发送的数据 2.新建word文档,这里我使用了word2010 点击工具栏邮件 开始邮件合并,电子邮件 选择收件人,使用现有列 ...

  4. YoC云上芯片家族迎来新成员

    Espressif 乐鑫信息科技(以下简称乐鑫科技)近日在上海召开发布会,发布其旗下最新的旗舰同时也是第二代Yun on Chip(简称YoC)云上芯片ESP32.YoC云上芯片是由YunOS牵头,联 ...

  5. winserver2012安装.net 3.5

    运行 dism.exe /online /enable-feature /featurename:NetFX3 /Source:I:\sources\sxs

  6. RabbitMQ学习笔记(6)----RabbitMQ 持久化和非持久化

    持久化:将交换机或队列数据保存到磁盘,服务器宕机或重启之后依然存在. 非持久化:将交换机或队列的数据保存到内存中,服务器宕机或重启之后数据将不存在. 在RabbitMQ中也提供了持久化和非持久化方式. ...

  7. Arguments Optional FreeCodeCamp

    function add() { if(typeof arguments[0] !== "number" || (arguments.length > 1 && ...

  8. tree -l命令参考

    一.简介 Keepalived是一个免费开源的,用C编写的类似于layer3, 4 & 7交换机制软件,具备我们平时说的第3层.第4层和第7层交换机的功能.主要提供loadbalancing( ...

  9. 在小程序中实现全局混入,以混入的形式扩展小程序的api

    GitHub: https://github.com/WozHuang/mp-extend 相关文章: 小程序全局状态管理,在页面中获取globalData和使用globalSetData 通过页面预 ...

  10. Vue学习之路第十二篇:为页面元素设置内联样式

    1.有了上一篇的基础,接下来理解内联样式的设置会更简单一点,先看正常的css内联样式: <dvi id="app"> <p style="font-si ...