Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout of CIA is very interesting, as there
is only one row so that every audience can enjoy the wonderful movies without any annoyance by other audiences sitting in front of him/her.

The ticket for CIA is strange, too. There are n seats in CIA and they are numbered from 1 to n in order. Apparently, n tickets will
be sold everyday. When buying a ticket, if there are k tickets left, your ticket number will be an integer i (1 ≤ i ≤ k), and you should choose the ith empty seat (not occupied by others) and sit down
for the film.

On November, 11th, n geeks go to CIA to celebrate their anual festival. The ticket number of the ith geek is ai. Can you help them
find out their seat numbers?

Input

The input contains multiple test cases. Process to end of file.

The first line of each case is an integer n (1 ≤ n ≤ 50000), the number of geeks as well as the number of seats in CIA. Then follows a line containing n integers a1a2, ..., an (1
≤ ai ≤ n - i + 1), as described above. The third line is an integer m (1 ≤ m ≤ 3000), the number of queries, and the next line is m integers, q1q2,
..., qm (1 ≤ qi ≤ n), each represents the geek's number and you should help him find his seat.

Output

For each test case, print m integers in a line, seperated by one space. The ith integer is the seat number of the qith geek.

Sample Input

3
1 1 1
3
1 2 3
5
2 3 3 2 1
5
2 3 4 5 1

Sample Output

1 2 3
4 5 3 1 2
题意:就是一排人看电影,票上安排给某人的位置是第几个空位。让你找出某些人的相应座位号。
线段树保存空位个数进行处理。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
const int maxn=50000+100;
int sum[maxn<<2];
int ans[maxn];
int n,m;
void pushup(int rs)
{
sum[rs]=sum[rs<<1]+sum[rs<<1|1];
}
void build(int rs,int l,int r)
{
sum[rs]=r-l+1;
if(l==r) return ;
int mid=(l+r)>>1;
build(rs<<1,l,mid);
build(rs<<1|1,mid+1,r);
pushup(rs);
}
int update(int rs,int l,int r,int x)
{
// cout<<"2333 "<<l<<" "<<r<<endl;
if(l==r)
{
sum[rs]=0;
return l;
}
int ret;
int mid=(l+r)>>1;
if(x<=sum[rs<<1]) ret=update(rs<<1,l,mid,x);
else ret=update(rs<<1|1,mid+1,r,x-sum[rs<<1]);
pushup(rs);
return ret;
}
int main()
{
int x;
while(~scanf("%d",&n))
{
CLEAR(sum,0);
CLEAR(ans,0);
build(1,1,n);
REPF(i,1,n)
{
scanf("%d",&x);
ans[i]=update(1,1,n,x);
}
scanf("%d",&m);
while(m--)
{
scanf("%d",&x);
printf(m==0?"%d\n":"%d ",ans[x]);
}
}
return 0;
}

ZOJ 3635 Cinema in Akiba(线段树)的更多相关文章

  1. ZOJ - 3635 Cinema in Akiba(树状数组+二分)

    题意:已知有n个人,从第一个人开始每个人被安排在第ai个空座上,有m组询问,问某人所坐的位置. 分析: 1.用树状数组维护空座的个数,方法: 将所有的空座初始化为1,sum(x)则表示从座位1到座位x ...

  2. ZOJ 3635 Cinema in Akiba[ 大规模阵列 ]

    门户:problemCode=3635">ZOJ 3635 Cinema in Akiba Time Limit: 3 Seconds      Memory Limit: 65536 ...

  3. ZOJ 3635 Cinema in Akiba (第一次组队) 树状数组+二分

    Cinema in Akiba Time Limit: 3 Seconds      Memory Limit: 65536 KB Cinema in Akiba (CIA) is a small b ...

  4. ZOJ 2671 Cryptography 矩阵乘法+线段树

    B - Cryptography Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  5. ZOJ 3911 Prime Query(线段树)

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  6. ZOJ 1610 Count the Color(线段树区间更新)

    描述Painting some colored segments on a line, some previously painted segments may be covered by some ...

  7. zoj 3888 Twelves Monkeys 二分+线段树维护次小值

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=3888 Twelves Monkeys Time Limit: 5 ...

  8. ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  9. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

随机推荐

  1. 执行shell脚本提示“syntax error near unexpected token for((i=0;i&lt;$length;i++))”

    sh脚本例如以下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 ...

  2. c# 未能载入文件或程序集

    近期做项目时碰到这个问题了.goole.百度了半天,整理了下面几种可能: DLL文件名称与载入时的DLL文件名称不一致, DLL文件根本不存在,即出现丢失情况, 载入DLL路径错误,即DLL文件存在, ...

  3. java--socket实现一个client像还有一个client发送信息

    首先建立接收方socket服务端 package com.haier.socket.server; import java.io.BufferedReader; import java.io.Inpu ...

  4. Python 中的用户自定义类型

    Python中面向对象的技术 Python是面向对象的编程语言,自然提供了面向对象的编程方法.但要给面向对象的编程方法下一个定义,是很困难的.问题关键是理解对象 的含义.对象的含义是广泛的,它是对现实 ...

  5. 跨服务器查询sql (摘要)

    首先推荐一个神作:http://www.cnblogs.com/daniel206/archive/2008/01/16/1041748.html 大神比较详细了.而且条理很清晰. 然后摘录一些其他的 ...

  6. SPSS Modeler数据挖掘项目实战(数据挖掘、建模技术)

    SPSS Modeler是业界极为著名的数据挖掘软件,其前身为SPSS Clementine.SPSS Modeler内置丰富的数据挖掘模型,以其强大的挖掘功能和友好的操作习惯,深受用户的喜爱和好评, ...

  7. javascript 如何获取return回来的对象值

    function aa(){ var b = 1; var c = b+2; return{ a1:b, a2:c } } var bb=aa(); alert(bb.a1);

  8. servlet后台怎样接收对象參数

    主要思想是用js把对象转换成json.然后把json提交到后台去,后台把这个json字符串转换成map对象 <script type="text/javascript"> ...

  9. DBA日常管理——数据归档(Archiving-Data)

    原文出处:http://www.sqlnotes.cn/post/2013/09/05/DBA-Daily-Jobs-One%E2%80%94%E2%80%94-Archiving-Data 均为本人 ...

  10. zabbix 监控jmx 需要--enable-java

    安装Javagateway如果原来已经安装zabbix,只需要再添加以下zabbix-java # tar zxvf zabbix-2.2.0.tar.gz # cd zabbix-2.2.0 # . ...