ZOJ 3635 Cinema in Akiba

简介: 题意:一群人到电影院看电影,该电影的门票计算比较特殊,如:甲第一个拿到1号门票则位置为1,乙第二个拿票,票号也是1,则位置为2,因为1号位置已经被甲占了,乙的位置为剩下位置中的1号位置。

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


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


题意:一群人到电影院看电影,该电影的门票计算比较特殊,如:甲第一个拿到1号门票则位置为1,乙第二个拿票,票号也是1,则位置为2,因为1号位置已经被甲占了,乙的位置为剩下位置中的1号位置。


思路:线段树入门,套模板。


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



相关文章
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8072 2
|
11天前
|
域名解析 人工智能 Linux
|
21天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
18755 64
|
19天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10140 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
5天前
|
人工智能 安全 网络安全
|
10天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1524 5
|
9天前
|
云安全 数据采集 人工智能
|
16天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2680 8
|
9天前
|
Web App开发 缓存 安全
巨魔商店 TrollStore 安装教程(2026):免电脑在线安装与全机型安装器矩阵_iOS巨魔安装
巨魔商店(TrollStore)是iOS 14–17.0(特定版本)的永久签名工具,无需越狱,利用CoreTrust漏洞实现IPA签名长期有效,彻底告别7天重签。支持免电脑在线安装(TrollHelperOTA),适配多机型/系统组合,开源免费,安全可控。(239字)
2259 0