In this cafeteria, the N tables are all ordered in one line, where table number 1 is the closest to the window and table number N is the closest to the door.

Each time a group of X people enter the cafeteria, one of the cafeteria staff escorts the guests to the table with the smallest number of chairs greater than or equal to X chairs among all available tables. If there’s more than one such table, the guests are escorted to the table that is closest to the window. If there isn't any suitable table available, the group will leave the cafeteria immediately. A table is considered available if no one sits around it.

Eyad likes to help others and also likes to prove that he has learned something from the training of Master Hasan. Therefore, he decided to write a program that helps the cafeteria staff choose the right table for a newly arriving group.

Given the log file of who entered and who left the cafeteria, find the table at which a given group should sit.

Input

The first line of input contains two integers N and Q (1 ≤ N, Q ≤ 105), the number of tables in the cafeteria and the number of events in the log file.

The second line contains N integers, each represents the size of a table (number of chairs around it). The tables are given in order from 1 to N. The size of each table is at least 1 and at most 105.

Each of the following Q lines describes an event in one of the following formats:

- in X: means a group of X (1 ≤ X ≤ 105) people entered the cafeteria.

- out T: means the group on table number T (1 ≤ T ≤ N) just left the cafeteria, the table is now available. It is guaranteed that a group was sitting on this table (input is valid).

Initially, all tables are empty, and the log lists the events in the same order they occurred (in chronological order).

Output

For each event of the first type, print the number of the table on which the coming group should sit. If for any event a group cannot be escorted to any table, print  - 1 for that event.

Example

Input
4 7
1 2 6 7
in 4
in 1
in 3
in 5
out 1
out 4
in 7
Output
3
1  
4
-1 做这题之前先来普及下 set<pair<int,int> > 的用法 注意:set<pair<int,int> >;      //     最后的> > 是     >空格>   否则会报错 其次
set<pair<int,int> >在头文件<set>中,并且要加上using namespace std;

<vector> 头文件    // iterator  迭代器迭代程序

set<pair<int,int> > // 是一种类,注意:定义的时候右边的两个> >要空一格。

在头文件<set>中

set<pair<int,int> > s   // 声明    s    s是类名,

set<pair<int,int> >::iterator it;     // iterator 迭代器迭代程序

lower_bound(key_value) 返回第一个大于等于key_value的定位器

upper_bound(key_value),返回最后一个大于等于key_value的定位器

假若上面查找的没有符合条件的,那么他们的值等于 s.end()

s.erase(it); 释放掉it的值

s.insert(make_pair(a[i],i)) 插入

it=s.lower_bound(make_pair(t,0));//寻找答案


ac代码:

#include<iostream>
#include<set>
#include<vector>
using namespace std;
const int maxn=1e5+10;
int n,q,a[maxn];
set<pair<int,int> > s; //最后两个> > 是 >空格> 否则会报错
set<pair<int,int> >::iterator it; // iterator 迭代器迭代程序
int main() //set默认的比较规则先按照first比较,如果first相同,再按照second 比较。
{
  cin>>n>>q;
  int i,x;
  char str[10];
  for (i=1;i<=n;i++){
    cin>>a[i];
    s.insert(make_pair(a[i],i)); //插入椅子数及其桌号
  }
  while (q--){
    cin>>str>>x;
    if (str[0]=='i'){
      it=s.lower_bound(make_pair(x,0)); //lower_bound(key_value) 返回第一个大于等于key_value的定位器
      if (it==s.end()){ //假若上面查找的没有符合条件的,那么他们的值等于 s.end()
        cout<<"-1\n";
        continue;
      }
      else{
      cout<<it->second<<endl;
      s.erase(it);//释放掉了桌号,相当于标记该桌号不能再用
       }
    }
    else{
      s.insert(make_pair(a[x],x));
    }
  }
return 0;
}

最新文章

  1. ASP.NET MVC一次删除多笔记录
  2. GDB调试命令小结
  3. 《机电传动控制》PLC仿真
  4. c# 正则提取小例子
  5. POJ 3185 The Water Bowls (高斯消元)
  6. mySql常用sql
  7. github/gitlab 管理多个ssh key
  8. hdu3231 (三重拓扑排序) 2009 Asia Wuhan Regional Contest Hosted by Wuhan University
  9. bootchart--检测linux启动性能的软件
  10. Destoon QQ互联一键登录审核不通过的解决方案
  11. web.xml中配置Spring中applicationContext.xml的方式
  12. 量化投资与Python之pandas
  13. python 2.7 读写 opc数据
  14. expect简单自动交互-用于密码、命令输入
  15. Sort功能极强!
  16. CouchDB 简单HTTP接口使用说明
  17. tian_lie
  18. Flutter 布局(九)- Flow、Table、Wrap详解
  19. SQL Server查看被锁的表 - dead lock
  20. 如何设置页面自动刷新第一篇?? servlet setHeader(&quot;refresh&quot;,&quot;2&quot;)

热门文章

  1. NO.005-2018.02.10《南歌子词二首 / 新添声杨柳枝词》唐代:温庭筠
  2. 第一次团队Scrum
  3. JsonResponse、FileResponse和StreamingHttpResponse
  4. bzoj 3028 生成函数
  5. POJ 2182 Lost Cows 【树状数组+二分】
  6. 作为PHP开发者请务必了解Composer
  7. asp.net中Page.ClientScript.RegisterStartupScript用法小结
  8. 【Calculus 微积分の一些个人理解】
  9. 在CentOs6.5下安装Python2.7.6和Scrapy
  10. CodeForces - 348A Mafia (巧妙二分)