ZOJ-3635-Cinema in Akba

Source: Internet
Author: User

ZOJ-3635-Cinema in Akba

Http://acm.zju.edu.cn/onlinejudge/showProblem.do? ProblemId = 4803

There are n slave 1 .. n indicates the number of seats in the order of time. When each guest arrives, he or she is seated in the first few empty seats. Finally, he/she asks a number of people where he/she is seated.

Line tree, And POJ-2828-Buy Tickets

#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;#define  N 50005struct cam{int x;int y;int count;}list[N*4];void build(int k,int x,int y){list[k].x=x;list[k].y=y;list[k].count=y-x+1;if(x==y)return;int mid=(x+y)/2;build(k<<1,x,mid);build(k<<1|1,mid+1,y);}int update(int k,int x){int ans;if(list[k].x==list[k].y){list[k].count=0;return list[k].x;}if(x<=list[k<<1].count)ans=update(k<<1,x);elseans=update(k<<1|1,x-list[k<<1].count);list[k].count=list[k<<1].count+list[k<<1|1].count;return ans;}int main(){int i,n,m,cur;int query[3005],ans[50005];while(scanf("%d",&n)!=EOF){build(1,1,n);for(i=1;i<=n;i++){scanf("%d",&cur);ans[i]=update(1,cur);}scanf("%d",&m);for(i=0;i<m;i++)scanf("%d",&query[i]);for(i=0;i<m;i++)printf(i==m-1?"%d\n":"%d ",ans[query[i]]);}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.