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;
}

set<pair<int,int> > 的运用的更多相关文章

  1. set<pair<int,int> >的用法

    例题链接:https://vjudge.net/contest/236677#problem/D 题意:首先输入两个数字n,m.n表示有n张桌子,编号从1到n,m表示有m个操作, 然后接下来一行有n个 ...

  2. C语言复杂声明-void (*signal(int sig, void (*handler)(int)))(int);

    问题提出 请分析此声明:void (*signal(int sig, void (*handler)(int)))(int); 求解过程 在对上面的例子作分析之前,我们需要了解C语言的声明优先级,&l ...

  3. Undefined symbols for architecture i386: "MyGetOpenALAudioData(__CFURL const*, int*, int*, int*)"

    今天把apple developer上的例子程序oalTouch中的MyOpenALSupport.h和MyOpenALSupport.c添加到自己的工程中,并在另一个文件xxx.cpp里调用,结果出 ...

  4. 自定义函数中的参数返回值 “-> (Int -> Int)”的问题

    func makeIncrementer() -> (Int -> Int) { func addOne(number: Int) -> Int { + number } retur ...

  5. void (*f(int, void (*)(int)))(int) 函数解析 转

    今天与几个同学看到了一个函数指针定义: void (*f(int, void (*)(int)))(int) 以前在C trap pit fails里面见过,但是文章里面介绍的很详细,但是往往使初学者 ...

  6. 如何理解这段代码:void (*signal (int sinno,void(*func)(int)))(int)

    void (*signal (int sinno,void(*func)(int)))(int) 先来看void(*func)(int)   这里的意思是声明一个函数指针func,它的参数类型为int ...

  7. 关于typedef int(*lpAddFun)(int, int)

    lpAddFun是typedef定义的一个名称 可以用来定义变量 比如 lpAddFun p; 那 p就是 int(*p)(int, int); 首先(*p)说明p是一个指针,(*p)();说明p指向 ...

  8. void (*f(int, void (*)(int)))(int) 函数解析

    函数指针 今天与几个同学看到了一个函数指针定义: void (*f(int, void (*)(int)))(int) 以前在C trap pit fails里面见过,但是文章里面介绍的很详细,但是往 ...

  9. 一道试题引发的血案 int *ptr2=(int *)((int)a+1);

    某日,看到一道比较恶心的C语言的试题,考了很多比较绕的知识点,嘴脸如下: int main(void) { int a[4] = {1, 2, 3, 4}; int *ptr1=(int *)(&am ...

随机推荐

  1. C#转Java之路之一:线程

    Java实现多线程方式有以下两种: public class HelloWordThread implements Runnable{ public void run(){ System.out.pr ...

  2. 不同系统里同一Customizing activity的显示差异分析

    比如SAP HANA Live Reporting这个Customizing Activity,在System AG3里不可见,但是在另一个系统QHD里却能使用.比较下列两张图的差异. 一种可能的原因 ...

  3. python27 文件读写

    fileobject = open(文件的绝对路径或相对路径,读写模式,其他可选参数) '''r-读 文件不存在报错FileNotFoundError''' try: f = open('file0. ...

  4. 小故事学设计模式之Command : (一) 在永和豆浆店

    IT的事就是过场多,过场多了就容易忘,所以我们不妨看一个记一个,这也是一个办法,顺便跟同行们学习交流一下)前几天出去拍照,饿到腿软, 回城附近有一家永和豆浆店, 我们决定去那边解决午餐.豆浆店里面还不 ...

  5. cocos2d-x3.1 下实现相似Android下ExpandListView的效果

    在左Android開始有SDK提供ExpandListView的可扩展列表,而在iOS下有很多第三方做好的Demo,这里我是參照iOS下RATreeView这个第三方库实现的. 本文代码:须要在3.1 ...

  6. HDU 5723 最小生成树上的期望

    题意:求最小生成树,和任意两个点之间距离的期望 官方题解: 最后求两遍点的积的时候,还是要判断父子关系. 注意 long long #include <bits/stdc++.h> usi ...

  7. Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】

    任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...

  8. 【洛谷P1801】黑匣子

    黑匣子 题目链接 看到题解中“维护两个堆”,突然想到了这道题的解法 维护两个堆:大根堆h1, 小根堆h2 大根堆里的是最小的i个值,小根堆里是剩下的值 每Add一个值时 插入到小根堆中, 再比较小根堆 ...

  9. 【洛谷P2296】[NOIP2014]寻找道路

    寻找道路 题目链接 这道题非常的水,按照题意, 先反向建边,从终点搜索,标记出可以到达终点的点 然后枚举一遍,判断出符合条件1的点 再从起点搜索一遍就可以了 #include<iostream& ...

  10. Flask—03-bootstrap与表单

    bootstrap与表单 Bootstrap是美国Twitter公司的设计师Mark Otto和Jacob Thornton合作基于HTML.CSS.JavaScript 开发的简洁.直观.强悍的前端 ...