ZOJ 3635 Cinema in Akiba【线段树】
来源:互联网 发布:淘宝买家退货率高后果 编辑:程序博客网 时间:2024/05/18 15:29
Cinema in Akiba
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 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 inCIA. Then follows a line containing n integers a1,a2, ..., 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,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 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
恩,题目大意就是说,电影院只有一排座位,每个到的人做的是第 ai 个空位置,然后问第 qi 个人所做的位置
#include <iostream>#include<cstdio>#include<cstring>#define maxn 50000+10using namespace std;struct lnode{ int l,r,c;};lnode node[maxn<<2];int ans[maxn];void pushup(int o){ node[o].c=node[o<<1].c+node[o<<1|1].c;}void build(int o,int l,int r){ node[o].l=l; node[o].r=r; node[o].c=r-l+1; if(l==r) return ; int mid=(l+r)>>1; build(o<<1,l,mid); build(o<<1|1,mid+1,r);}int update(int o,int a){ if(node[o].l==node[o].r) { node[o].c=0; return node[o].l; } int ans=0; if(a<=node[o<<1].c) ans=update(o<<1,a); else ans=update(o<<1|1,a-node[o<<1].c); pushup(o); return ans;}int main(){ int n,m,a; while(~scanf("%d",&n)) { memset(ans,0,sizeof(ans)); build(1,1,n); for(int i=1;i<=n;++i) { scanf("%d",&a); ans[i]=update(1,a); } scanf("%d",&m); for(int i=1;i<=m;++i) { scanf("%d",&a); if(i!=m) printf("%d ",ans[a]); else printf("%d\n",ans[a]); } } return 0;}
- ZOJ 3635 Cinema in Akiba【线段树】
- ZOJ 3635 Cinema in Akiba(线段树)
- ZOJ 题目3635 Cinema in Akiba(线段树插空)
- ZOJ-3635-Cinema in Akiba
- ZOJ 3635 Cinema in Akiba
- zoj 3635 Cinema in Akiba
- ZOJ 3635 Cinema in Akiba[ 块状数组 ]
- ZOJ 3635 Cinema in Akiba(树状数组 + 二分)
- Poj 2828 Buy Tickets \ Zoj 3635 Cinema in Akiba
- ZOJ 3635 Cinema in Akiba (树状数组+二分)
- zoj 3635 Cinema in Akiba(树状数组+二分)
- ZOJ 3635 Cinema in Akiba(二分+树状数组)
- zoj 3635 Cinema in Akiba 二分+树状数组
- ZOJ3635 Cinema in Akiba
- zoj3635 Cinema in Akiba
- ZOJ 3635——Cinema in Akiba(树状数组+二分)
- zoj 3635 Cinema in Akiba 树状数组求第K大
- ZOJ Monthly, August 2012 - C Cinema in Akiba 树状数组+二分
- dos中如何编译机器码
- 我想要个好看的404,哈哈
- Android适配全攻略
- hdu5381The sum of gcd 线段树+set
- net.sf.hibernate.MappingException
- ZOJ 3635 Cinema in Akiba【线段树】
- maven之Nexus的配置【pom.xml配置<repositories>】(五)
- C#与Java基础语法初比较
- 字符串压缩
- 深入理解iOS API系列(四)理解CNContactPickerDelegate
- net.sf.hibernate.PropertyNotFoundExceptio
- 【二叉树】关于二叉树的后续遍历遍历以及栈
- C语言/函数指针
- 【LEETCODE】96-Unique Binary Search Trees