http://codeforces.com/contest/982/problem/B
一开始没有想到模拟栈,用while来寻找introve的位置,超时
#include <iostream>
#include <queue>
#include <stdio.h>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long ll;
struct Seat
{
ll row,w;
short empty;
Seat()
{
empty=2;
}
bool operator<(const Seat& a)const
{
if(w!=a.w) return w<a.w;
else return empty<a.empty;
}
}seat[200005];
stack<int> qq;
int main()
{
int num;
string s;
while(cin>>num)
{
for(int i=1; i<=num; i++)
{
seat[i].row=i;
scanf("%I64d",&seat[i].w);
}
cin>>s;
sort(seat+1,seat+1+num);
int bothp=1,onep=1;
for(int i=0; i<s.length(); i++)
{
if(s[i]=='0')
{
printf("%I64d ",seat[bothp].row);
seat[bothp].empty--;
qq.push(bothp);
bothp++;
}
else if(s[i]=='1')
{
printf("%I64d ",seat[qq.top()].row);
seat[qq.top()].empty--;
qq.pop();
}
}
}
return 0;
}