前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ZOJ 3635 Cinema in Akiba

ZOJ 3635 Cinema in Akiba

作者头像
Java架构师必看
发布2021-05-14 10:30:05
3810
发布2021-05-14 10:30:05
举报
文章被收录于专栏:Java架构师必看

Cinema in Akiba


Time Limit: 3 Seconds     

Memory Limit: 65536 KB


Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout ofCIA 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 integeri (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 theith geek isai. 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 inCIA. Then follows a line containingn integers a1,a2, ..., an (1 ≤ ai ≤n - i + 1), as described above. The third line is an integerm (1 ≤m ≤ 3000), the number of queries, and the next line ism integers,q1, q2, ..., 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. Theith integer is the seat number of theqith geek.

Sample Input
代码语言:javascript
复制
3
1 1 1
3
1 2 3
5
2 3 3 2 1
5
2 3 4 5 1
Sample Output
代码语言:javascript
复制
1 2 3
4 5 3 1 2
代码语言:javascript
复制
题意:一群人到电影院看电影,该电影的门票计算比较特殊,如:甲第一个拿到1号门票则位置为1,乙第二个拿票,票号也是1,则位置为2,因为1号位置已经被甲占了,乙的位置为剩下位置中的1号位置。
代码语言:javascript
复制
思路:线段树入门,套模板。
代码语言:javascript
复制
代码语言:javascript
复制
#include<stdio.h>
#include<cstdio>
#define inf 55555
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int sum[inf];
int a[inf];
int b[inf];
int c;
void build(int l,int r, int rt)
{
    sum[rt]=r-l+1;
    if(l==r)
		return;
    int m=(l+r)>>1;
    build(lson);
    build(rson);
}
int update(int p,int l,int r,int rt)
{
    sum[rt]--;
    if(l==r)
		return l;
    int m=(l+r)>>1;
    if(p<=sum[rt<<1])
       return update(p,lson);
    else
       return update(p-sum[rt<<1],rson);
}
int main()
{
	int m,i,n;
	while(scanf("%d",&n)!=EOF)
	{
		build(1,n,1);
		for(i=1;i<=n;i++)
		{
			scanf("%d",&c);
			a[i]=update(c,1,n,1);
		}
		scanf("%d",&m);		
		for(i=1;i<=m;i++)
		{
			scanf("%d",&b[i]);
		}
		for(i=1;i<m;i++)
			printf("%d ",a[b[i]]);
		printf("%d\n",a[b[m]]);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Input
  • Output
  • Sample Input
  • Sample Output
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档