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),很是奇怪,于是上网找资料 ...
随机推荐
- 如何用代码开启“个人热点”功能?如何用代码把iOS设备设置成一个无线路由?
不好意思,你办不到.苹果不允许.因为你没有权限.
- CSS之照片翻转
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- Android从imageview中获得bitmap
第一种: 使用setDrawingCacheEnabled()和getDrawingCache()这两种方法,第一个是为了设置是否开启缓存,第二个就可以直接获得imageview中的缓存,一般来说需要 ...
- Cocos开发中性能优化工具介绍之使用Windows任务管理器
说到Windows平台,我们很快就想到了Visual Studio 2012,然而Visual Studio 2012在这方面没有很好的工具.如果我们只是想知道大体上内存.CPU等在某一事件前后变化情 ...
- 设置一个View的背景图片的集中方法
控制器view的背景图片的方法, 四种: 1.直接在控制器view上添加一个imageView大小设置的和view一样 UIImageView *beijingimage = [UIImageView ...
- [zz] 安装PostGIS(Linux篇)
0.安装PostgreSQL数据库 参考安装PostgreSQL数据库(Linux篇). 1.安装proj4 #tar zxvf proj-4.8.0.tar.gz#cd proj-4.8.0#./c ...
- spring aop配置及用例说明(2)
欢迎交流转载:http://www.cnblogs.com/shizhongtao/p/3473362.html 这里先介绍下几个annotation的含义, @Before:表示在切入点之前执行. ...
- C#,PHP对应加密函数
require_once "JunDes.php"; $jDes=new JunDes(); echo $jDes->encode('98765'); //echo $jDe ...
- IOS 四种保存数据的方式
在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题.将数据保存到本地,能够让程序的运行更加流畅,不会出现让人厌恶的菊花形状,使得用户体验更好.下面介绍一下数据保存的方式: 1.NSKeyed ...
- amcharts 网页绘图插件
Amcharts是一组js图表,你可以免费使用在你的网站和基于网络的产品(非开源). Amcharts可以从简单的json提取数据,也可以从动态数据读取生成,比如PHP, .NET, Ruby on ...