博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 3635 Cinema in Akiba(线段树)
阅读量:6267 次
发布时间:2019-06-22

本文共 2605 字,大约阅读时间需要 8 分钟。

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

31 1 131 2 352 3 3 2 152 3 4 5 1

Sample Output

1 2 34 5 3 1 2
题意:就是一排人看电影,票上安排给某人的位置是第几个空位。让你找出某些人的相应座位号。
线段树保存空位个数进行处理。

 
#include
#include
#include
#include
#include
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 "<
<<" "<
<
>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;}

转载地址:http://pudpa.baihongyu.com/

你可能感兴趣的文章
PHP根据ASCII码返回具体的字符
查看>>
atitit.系统架构图 的设计 与工具 attilax总结
查看>>
URAL 1774 A - Barber of the Army of Mages 最大流
查看>>
处理器(CPU)调度问题
查看>>
leetcode - 位运算题目汇总(下)
查看>>
多少个矩形被覆盖
查看>>
22、ASP.NET MVC入门到精通——搭建项目框架
查看>>
3-7 类的友元函数的应用
查看>>
IntelliJ IDEA安装 一些配置
查看>>
【算法之美】求解两个有序数组的中位数 — leetcode 4. Median of Two Sorted Arrays
查看>>
post请求和get请求
查看>>
零成本实现接口自动化测试 – Java+TestNG 测试Restful service
查看>>
源码安装php时出现Sorry, I cannot run apxs. Possible reasons follow:
查看>>
使用T4模板生成POCO类
查看>>
精度 Precision
查看>>
打印内容函数
查看>>
Mina2 udp--zhengli
查看>>
组合模式
查看>>
Checked Exceptions
查看>>
Android——4.2 - 3G移植之路之 APN (五)
查看>>