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),很是奇怪,于是上网找资料 ...
随机推荐
- 关于WIFI的工作模式--AP MODE/STATION MODE
wifi的concurrent mode 所谓wifi的共存模式,有以下几种: station mode + station mode station mode + ap mode station m ...
- 淘淘实惠多www.taohuiduo.com-专注独家折扣、1折特卖、9块9包邮、全场包邮
淘淘实惠多-http://www.taohuiduo.com 专注独家折扣.1折特卖.9块9包邮.品牌折扣.20元封顶.全场包邮,所有的促销商品包括男装.女装.箱包配饰.母婴.日用.化妆品.数码.男鞋 ...
- 感受函数式编程-scala
/** * Created by jx_luo on 2015/3/18. */object test03 { def main(Args:Array[String]): Unit ={ val st ...
- 使用 EF Power Tool Code Frist 生成 Mysql 实体
原文:使用 EF Power Tool Code Frist 生成 Mysql 实体 1,在要生成的项目上右键 2, 3, 4, 5, 生成后的效果 已知问题: 1,在Mys ...
- CKedit在线编辑器
在线编辑器 在实现所见即得的编辑效果. FCK 是开发者的名字的缩写 CKEditor 功能很完善的,具有,在线编辑与图片上传JS插件 UEdit ...
- VisualLeakDetector
只需要#include "vld.h"就OK -------------------------------------- 找内存泄露挺方便的,比VS自带的详细.
- Qt 串口通信
在Qt5之前,串口通信基本依赖于第三方库,下面是我曾接触过的串口通信类库: 名称 语言 平台 QextSerialPort QT C++ Win/Linux http://sourceforge. ...
- Nhibernate的log4net和系统的log4net使用技巧
NHibernate定义了两个logger:NHibernate和NHibernate.SQL.我们可以分别配置这两个logger.在App.config文件中<root>标签前边添加如下 ...
- maven增量编译
最近由于不清楚maven(2.2.x)增量编译的机制,导致应用出现了一个当时觉得非常诡异的一个问题.先描述一下问题. 背景是应用A有一个公用的base包,版本为1.6.6-SNAPSHOT,应 ...
- MIT 2012 分布式课程基础源码解析-底层通讯实现
本节内容和前节事件管理封装是息息相关的,本节内容主要包含的代码在connection{.h, .cc}中. 这里面最主要的有两个类:connection类和tcpsconn类,connetion类主要 ...