您的位置:首页 > Web前端

CodeForces Gym 100989D 1D Cafeteria (B) SET

2016-07-14 18:19 781 查看
读懂题之后就简单很多,就是一个pair<int,int>,然后用set维护就行
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
#define ll long long
#define maxn 100005
int N, Q;
int num[maxn];
set< pair<int, int> > table;
set< pair<int, int> >::iterator itor;
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
scanf("%d%d", &N, &Q);
for (int i = 1; i <= N; ++i)
{
scanf("%d", &num[i]);
table.insert(make_pair(num[i], i));
}
char cmd[10];
int tmp;
while (Q--)
{
scanf("%s%d", cmd, &tmp);
if (cmd[0] == 'i')
{
itor = table.lower_bound(make_pair(tmp, 0));
if (itor == table.end())
{
printf("-1\n");
}
else
{
printf("%d\n", itor->second);
table.erase(itor);
}
}
else
{
table.insert(make_pair(num[tmp], tmp));
}
}
//system("pause");
//while (1);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: