读懂题之后就简单很多,就是一个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;
}

本文介绍了一种利用C++ STL中的set数据结构来高效处理pair数据的方法。通过对输入数据进行排序并跟踪其索引,该算法实现了快速查找和删除特定元素的功能。适用于需要频繁查询与更新的数据集。
3753

被折叠的 条评论
为什么被折叠?



