zoj 3635 Cinema in Akiba

来源:互联网 发布:域名泛解析怎么做 编辑:程序博客网 时间:2024/06/05 11:53

裸线段树,水题1A之。

/*########################################################################## File Name: c.cpp# Author: CaoLei# Created Time: 2015/7/13 14:15:38#########################################################################*/#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <set>#include <queue>#include <map>using namespace std;#define MAX(x,y) (((x)>(y))?(x):(y))#define MIN(x,y) (((x)<(y))?(x):(y))#define N 500010#define pi acos(-1.0)#define inf 100000000typedef long long ll;typedef unsigned long long ull;struct tre{int l, r;int len;}tree[200000];int ans[50010];void build(int root, int l, int r){tree[root].l = l;tree[root].r = r;tree[root].len = r - l + 1;  if (l == r) return;build(root*2, l, (l + r) / 2);build(root*2+1, (l + r) / 2 + 1, r);}int query(int root, int k){tree[root].len--;if (tree[root].l == tree[root].r) return tree[root].l;else if (k>tree[root*2].len)return query(root *2 + 1, k - tree[root << 1].len);else return query(root * 2, k);}int main(){//freopen("in.txt", "r", stdin);int n, m;int tmp;while (~scanf("%d", &n)){memset(tree, 0, sizeof(tree));memset(ans, 0, sizeof(ans));build(1, 1, n);for (int i = 1; i <= n; i++){scanf("%d", &tmp);ans[i] = query(1, tmp);//printf("%d ", ans[i]);}//printf("\n");scanf("%d", &m);for (int i = 1; i < m; i++){scanf("%d", &tmp);printf("%d ", ans[tmp]);}        scanf("%d",&tmp);printf("%d\n",ans[tmp]);}return 0;}


0 0
原创粉丝点击