留着

#include <cstdio>
#include <cstring>
#include <cstdlib> #define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1 const int MAXN = 200010; int pos[MAXN];
int sum[MAXN << 2];// = MAXN*4
int ans[MAXN];
int N, id; void build( int l, int r, int rt )
{
sum[rt] = r - l + 1;
if ( l == r ) return; int m = ( l + r ) >> 1;// = (l+r)/2
build( lson );
build( rson );
return;
} void Update( int po, int l, int r, int rt )
{
--sum[rt];
if ( l == r )
{
id = l;
return;
} int m = ( l + r ) >> 1;// = (l+r)/2 if ( po <= sum[rt << 1] ) Update( po, lson ); // = rt*2
else Update( po - sum[rt << 1], rson ); // = rt*2 return;
} int main()
{
int T;
scanf( "%d", &T );
while ( T-- )
{
scanf( "%d", &N );
build( 1, N, 1 );
for ( int i = 1; i <= N; ++i )
scanf( "%d", &pos[i] ); for ( int i = N; i > 0; --i )
{
int addr = i - pos[i]; //还剩几个数
Update( addr, 1, N, 1 );
ans[i] = id;
//printf( "%d\n", id );
}
printf( "%d", ans[1] );
for ( int i = 2; i <= N; ++i )
printf( " %d", ans[i] );
puts("");
}
return 0;
}

spoj 227的更多相关文章

  1. SPOJ 227 Ordering the Soldiers 线段树 / 树状数组

    题意:设原数组为a[i],pos[i]代表第 i 个位置之前有多少个数比a[i]大,求原数组a[i]. 这个题意是看了别人的题解才明白,我自己没读出来…… 方法:假设我们从左往右放,因为后面的数还有可 ...

  2. SPOJ 227 Ordering the Soldiers

    As you are probably well aware, in Byteland it is always the military officer's main worry to order ...

  3. Android Weekly Notes Issue #227

    Android Weekly Issue #227 October 16th, 2016 Android Weekly Issue #227. 本期内容包括: Google的Mobile Vision ...

  4. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  5. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  6. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  7. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  8. 227 Entering Passive Mode (xxx,xxx,,xxx,xxx,x)

    登录ftp时显示227 Entering Passive Mode (xxx,xxx,,xxx,xxx,x) 因为FTP有两种工作模式,PORT方式和PASV方式,中文意思为主动式和被动式 ,详细介绍 ...

  9. FTP连接时出现“227 Entering Passive Mode” 的解决方法

    今天从公网的服务器连接本地内网的FTP server copy文件时,系统老是提示227 Entering Passive Mode (xxx,xxx,,xxx,xxx,x),很是奇怪,于是上网找资料 ...

随机推荐

  1. dotnetbar 的BalloonTip的用法

    ‘设置提示标题 tip.SetBalloonCaption(txt_ID, "提示") ’设置显示的控件 和显示内容文本 tip.SetBalloonText(txt_ID, &q ...

  2. block回调具体例子

    //main.m ////  main.m//  回调////  Created by hehe on 15/9/10.//  Copyright (c) 2015年 wang.hehe. All r ...

  3. bzoj3389:[Usaco2004 Dec]Cleaning Shifts安排值班

    思路:可以贪心,也可以最短路. 贪心写法:因为在保证合法的前提下,我们选择的区间一定要右端点尽量靠后才行,于是我们每次就选择一个合法的并且右端点最靠后的区间就好了(如果没有合法的输出-1即可).时间复 ...

  4. 动态链接库加载出错:cannot restore segment prot after reloc: Permission denied

    在执行可执行程序时,出现动态链接库加载出错:cannot restore segment prot after reloc: Permission denied. 主要是由于Linux 内核中提供的强 ...

  5. Contest1065 - 第四届“图灵杯”NEUQ-ACM程序设计竞赛(个人赛)G爬楼梯

    题目描述 由于第m个台阶上有好吃的薯条,所以薯片现在要爬一段m阶的楼梯. 薯片每步最多能爬k个阶梯,但是每到了第i个台阶,薯片身上的糖果都会掉落ai个,现在问你薯片至少得掉多少糖果才能得到薯条? 输入 ...

  6. 再说 extern "C"

    早知道 C++ 源文件中要调用C语言函数需要在函数申明时 指定extern "C": 要不然可以编译通过,但连接时提示找不到什么什么符号,原因是C和C++生成的函数名不一样,ext ...

  7. Jquery 页面元素动态添加后绑定事件丢失方法,非 live

    代码1: 以此方法绑定的input框事件,在通过add按钮后用jquery绑定的事件 alert就会丢失 <input type="button" value="A ...

  8. 解决CxGrid Filter 后,通过 Dataset 循环时得出的结果与 Grid显示不同步的问题.

    // 方案1: 强制cxgrid 使用 dataset的 Filter GridMaster.DataController.Filter.AutoDataSetFilter := True; /// ...

  9. python的浅拷贝和深拷贝

    python对象有两种拷贝的形式:浅拷贝和深拷贝. 在<python核心编程>中看到对这两种拷贝的分析,觉得十分收益,所以记录在此. id()方法:id()方法可以查看某个对象的ID,类似 ...

  10. gc overhead limit exceeded

    eclipse-- gc overhead limit exceeded 修改内存不足的方法如下: Eclipse报错:gc overhead limit exceeded eclipse 原因是Ec ...