spoj 227
留着
#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的更多相关文章
- SPOJ 227 Ordering the Soldiers 线段树 / 树状数组
题意:设原数组为a[i],pos[i]代表第 i 个位置之前有多少个数比a[i]大,求原数组a[i]. 这个题意是看了别人的题解才明白,我自己没读出来…… 方法:假设我们从左往右放,因为后面的数还有可 ...
- SPOJ 227 Ordering the Soldiers
As you are probably well aware, in Byteland it is always the military officer's main worry to order ...
- Android Weekly Notes Issue #227
Android Weekly Issue #227 October 16th, 2016 Android Weekly Issue #227. 本期内容包括: Google的Mobile Vision ...
- 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 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- 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 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- 227 Entering Passive Mode (xxx,xxx,,xxx,xxx,x)
登录ftp时显示227 Entering Passive Mode (xxx,xxx,,xxx,xxx,x) 因为FTP有两种工作模式,PORT方式和PASV方式,中文意思为主动式和被动式 ,详细介绍 ...
- FTP连接时出现“227 Entering Passive Mode” 的解决方法
今天从公网的服务器连接本地内网的FTP server copy文件时,系统老是提示227 Entering Passive Mode (xxx,xxx,,xxx,xxx,x),很是奇怪,于是上网找资料 ...
随机推荐
- HDOJ2021发工资咯:)
发工资咯:) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Jquery选择器 讲解
在Dom 编程中我们只能使用有限的函数根据id 或者TagName 获取Dom 对象. 然而在jQuery 中则完全不同,jQuery 提供了异常强大的选择器用来帮助我们获取页面上的对象, 并且将对象 ...
- github果然强大
github果然强大,在idea里写好,可以直接提交到github,在哪台电脑都可以看源码了,手机也可以看 https://github.com/gaojinhua
- (Android)View.getHeight或getWidth为0时的一些解决方案
在Android开发过程中,经常需要动态的更改View的大小,有些View的大小可能需要根据其他View的大小来设定,或者你需要得到一些View的大小来进行某项操作,但是有可能你需要在onCreate ...
- 转:SqlServer2008误操作数据(delete或者update)后恢复数据
Sqlserver2008误操作数据(delete或者update)后恢复数据(转) 实际工作中,有时会直接在数据库中操作数据,比如对数据进行delete或者update操作,当进行这些操作的时候,如 ...
- StrictMode模式介绍
最新的Android平台中(Android 2.3起),新增加了一个新的类,叫StrictMode(android.os.StrictMode).这个类可以用来帮助开发者改进他们编写的应用,并且提供了 ...
- VS2013 打开项目时出现 未定义标识符string的解决办法
---恢复内容开始--- 前两天从前辈那儿弄到一份源码,VC 6时期写出来的mfc程序. 打开之后直接编译编译成功,可以运行.但是看代码的时候却发现出现了好多错误,如 未定义标识符string,NUL ...
- out ref区别
1.使用ref型参数时,传入的参数必须先被初始化.对out而言,必须在方法中对其完成初始化. 2.out适合用在需要retrun多个返回值的地方,而ref则用在需要被调用的方法修改调用者的引用的时候. ...
- 如何管好.net的内存(托管堆和垃圾回收)
一:C#标准Dispose模式的实现 需要明确一下C#程序(或者说.NET)中的资源.简单的说来,C#中的每一个类型都代表一种资源,而资源又分为两类: 托管资源:由CLR管理分配和释放的资源,即由CL ...
- java计算过G文件md5 值计算
package io.bigdata; import java.io.File; import java.io.FileInputStream; import java.io.IOException; ...