日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 互聯(lián)網(wǎng) > ZOJ 3635 Cinema in Akiba(線段樹)

ZOJ 3635 Cinema in Akiba(線段樹)

來源:程序員人生   發(fā)布時間:2014-11-20 08:11:51 閱讀次數(shù):2229次

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
題意:就是1排人看電影,票上安排給某人的位置是第幾個空位。讓你找出某些人的對應(yīng)坐位號。
線段樹保存空位個數(shù)進(jìn)行處理。
#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
":"%d ",ans[x]);
        }
    }
    return 0;
}



生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 玖玖视频| 国产精品v | 国内久久精品视频 | 精品久久久久久久久久久下田 | 国产精品99久久久久久似苏梦涵 | 亚洲成人在线网站 | 欧美在线播放 | 国产激情一区二区三区在线观看 | 精品视频入口 | 国产精品一区一区三区 | 久久国精品 | 国产视频a| 国产aaa精品 | 日韩精品免费在线视频 | 中文欧美日韩 | 久久久一二三 | 欧美国产精品一区二区三区 | 成人短视频在线观看 | 日韩成人av电影 | 欧美激情第1页 | 国产精品视频1区 | 草久草久 | 午夜久久av | 男女爱爱免费视频 | 麻豆亚洲一区 | 精品视频久久久久久 | 国产视频中文字幕 | 中文在线中文a | 欧美在线一区二区 | 精品久久久久久久久久久久 | 一区二区av在线 | 精品久久久av | 91啦蝌蚪视频 | 一区二区三区在线免费视频 | 日韩欧美中出 | 午夜精品久久久久久久爽 | 日韩精品一二三 | 亚洲综合第一页 | 欧美一区二区三区免费看 | 一级国产| av片免费在线播放 |