Codeforces Round #484 (Div. 2) B. Bus of Characters(markdowm版)

Codeforces Round #484 (Div. 2) B. Bus of Characters

B. Bus of Characters

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

In the Bus of Characters there are nn rows of seat, each having 22 seats. The width of both seats in the ii-th row is wiwi centimeters. All integers wiwi are distinct.

Initially the bus is empty. On each of 2n2n stops one passenger enters the bus. There are two types of passengers:

an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;

an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it.

You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.

Input

The first line contains a single integer nn (1≤n≤2000001≤n≤200000) — the number of rows in the bus.

The second line contains the sequence of integers w1,w2,…,wnw1,w2,…,wn (1≤wi≤1091≤wi≤109), where wiwi is the width of each of the seats in the ii-th row. It is guaranteed that all wiwi are distinct.

The third line contains a string of length 2n2n, consisting of digits ‘0‘ and ‘1‘ — the description of the order the passengers enter the bus. If the jj-th character is ‘0‘, then the passenger that enters the bus on the jj-th stop is an introvert. If the jj-th character is ‘1‘, the the passenger that enters the bus on the jj-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal nn), and for each extrovert there always is a suitable row.

Output

Print 2n2n integers — the rows the passengers will take. The order of passengers should be the same as in input.

Examples

input

Copy

2

3 1

0011

output

Copy

2 1 1 2

input

Copy

6

10 8 9 11 13 5

010010011101

output

Copy

6 6 2 3 3 1 4 4 1 2 5 5

Note

In the first example the first passenger (introvert) chooses the row 22, because it has the seats with smallest width. The second passenger (introvert) chooses the row 11, because it is the only empty row now. The third passenger (extrovert) chooses the row 11, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row 22, because it is the only row with an empty place*

【题意】:

就是说有一辆公交车,有n排;

接下来n个数据代表n排的权值(每排只能坐2个人);

然后接下来又2*n的数据

代表要坐入这辆公交车的人的类型。

1代表外向型,0代表内向型。

外向型:优先选择旁边有人的且权值最大的位置,如果没有的话,选择权值最大的位置。

内向型:优先选择没人的位置且权值最小的位置。

【思路】:

我使用了四个优先队列进行数据的维护。

第一个队列,按权值从小到大维护;

第二个队列,按权值从大到小维护;(ps:代码实现的时候,我使用第一个维护大的,第二个维护小的)

第三个队列,代表被选择的位置,按从小到大维护;(ps:其实第三个队列意义不大,因为后面没有使用的)

第四个队列,代表被选择的位置,按从大到小维护;

使用了一个位置来标记是否使用过。

输入0,判断第一个队列是否还有值,有的话,压入第三个队列,和第四个队列

代表被使用了。顺带把答案放到输出数组里。

输入1,判断第四个队列中是否有值,有的话,就选择维护的第一个。因为肯定是

有人的最大权值。把第一个放入输出数组。

如果第四个队列中没有值,那就只能从第二队列中取出第一个。把(第一个)答案放到输出数组中。

(其实这个题目给的数据都是合法的。因为他保证0都坐得进去。)

附上代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int MAXN = 2*1e5+5;
typedef struct NODE
{
    int math;
    int flag;
    friend bool operator < (NODE a, NODE b)
    {
        return a.math > b.math;    //重载小于号使得小的先出队列
    }
} node;
node team[MAXN];
node team1[MAXN];
int bj[MAXN];
int people[MAXN*2];
priority_queue<node>que1;///保存大的值
priority_queue<node>que2;///保存小的值
priority_queue<node>que3;///保存结果
priority_queue<node>que4;///保存另一个结果
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(team,0,sizeof(team));
        memset(bj,0,sizeof(bj));
        memset(people,0,sizeof(people));
        while(!que3.empty())
        {
            que3.pop();
        }
        while(!que1.empty())
        {
            que1.pop();
        }
        while(!que2.empty())
        {
            que2.pop();
        }
        while(!que4.empty())
        {
            que4.pop();
        }
        for(int i=0; i<n; i++)
        {
            scanf("%d",&team[i].math);
            team1[i].math=-team[i].math;
            team1[i].flag=i;
            team[i].flag=i;
            que1.push(team1[i]);
            que2.push(team[i]);
        }
        char str[MAXN*2];
        scanf("%s",str);
        for(int i=0; i<n*2; i++)
        {
            int ans;
            ans=str[i]-‘0‘;
            if(ans==0)
            {//printf("!!!!\n");
                if(!que1.empty())
                {
                    node ans1=que2.top();
                    //printf("%d\n",ans1.math);
                    que2.pop();
                    if(bj[ans1.flag]==0)
                    {
                        que3.push(ans1);
                        bj[ans1.flag]=1;
                        people[i]=ans1.flag+1;
                        ans1.math=-ans1.math;
                        que4.push(ans1);
                    }
                }
            }
            if(ans==1)
            {//printf("..?.\n");
                if(!que4.empty())
                {
                    node ans2;
                    ans2=que4.top();
                    que4.pop();
                    people[i]=ans2.flag+1;
                }
                else
                    if(que4.empty())
                {
                    node ans3;
                    ans3=que1.top();
                    que1.pop();
                    bj[ans3.flag]=1;
                    people[i]=ans3.flag+1;
                }
            }
        }
        for(int i=0;i<2*n;i++)
            printf("%d ",people[i]);
        puts("");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/qq136155330/p/9069895.html

时间: 2024-10-10 06:33:52

Codeforces Round #484 (Div. 2) B. Bus of Characters(markdowm版)的相关文章

Codeforces Round #436 (Div. 2) C. Bus

Codeforces Round #436 (Div. 2) C. Bus A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the pointx = a, immediately turns back and then moves to the point x = 0. After re

Codeforces Codeforces Round #484 (Div. 2) E. Billiard

Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/problem/E Description Consider a billiard table of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at t

Codeforces Codeforces Round #484 (Div. 2) D. Shark

Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D Description For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and

Codeforces Round #481 (Div. 3) E. Bus Video System

E. Bus Video System Example 1 input 3 5 2 1 -3 output 3 Example 2 input 2 4 -1 1 output 4 Example 3 input 4 10 2 4 1 2 output 2 题目大意: 车上只会显示y-x(y是离开站时的人数,x时到站前的人数),问第一站的人数可以有几种 分析: 我们先分析下这个数学问题的式子,设a[i]=y[i]-x[i]--① x[i+1]=y[i],这是显然易见的 然后我们将①从1到n项累加

Codeforces Round #491 (Div. 2) E - Bus Number + 反思

E - Bus Number 最近感觉打CF各种车祸.....感觉要反思一下, 上次读错题,这次想当然地以为18!肯定暴了longlong 而没有去实践, 这个题我看到就感觉是枚举每个数字的个数,但是我觉得算得时候会爆longlong 就想用大数,但是我去看别人交的全部都是C++,就感觉是不是有别的方法, 想了半天感觉时间来不及了就强行上了个java,结果时间来不及... 以后写题首先要读清楚题目,其次不要想当然,要去实践!!!!!!!!!!! 真的很烦. import java.math.Bi

【set】【multiset】Codeforces Round #484 (Div. 2) D. Shark

题意:给你一个序列,让你找一个k,倘若把大于等于k的元素都标记为不可用,那么剩下的所有元素形成的段的长度相同,并且使得段的数量尽量大.如果有多解,输出k尽量小的. 把元素从大到小排序插回原位置,用一个set维护前驱后继,相当于删除一个原有的段,然后将这个段切成两半,产生两个新的段.维护这次操作后所有段的长度以及各种长度的出现次数(用multiset),一旦合法,就尝试更新答案. #include<cstdio> #include<algorithm> #include<set

Codeforces Round #484 (Div. 2)

Link A.B 签到 C 分析 赛时wa7起不来 D 题意 分析 原文地址:https://www.cnblogs.com/Deadline/p/9058253.html

Codeforces Round #484 (Div. 2) A. Row

A. Row time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You're given a row with nn chairs. We call a seating of people "maximal" if the two following conditions hold: There are no neigh

Codeforces Round #261 (Div. 2)

A. Pashmak and Garden 题意:已知两个顶点的坐标,如果能推断出另外两个顶点则输出(special judge).如果这两个顶点不是构成正方形的两个顶点, 则输出-1. 水题,1A,不多说. #include<cstdio> #include<iostream> #include<cstring> #include<cmath> using namespace std; int main() { int x1,x2,y1,y2,flag,x