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; }
相关文章推荐
- ButterKnife使用详解
- node.js 下依赖Express 实现post 4种方式提交参数
- 用JS获取地址栏参数的方法(超级简单)
- js中的数组操作
- struts1+ajax+jquery上传文件
- CodeForces Gym 100989C 1D Cafeteria (A)
- 剑指offer 8题 【查找和排序 】旋转数组的最小数字
- js定时相关函数:
- chartjs
- js中的三大对象
- 实现页面倒数秒后跳转到指定页面
- 简单javascript的使用
- javaScript百度地图
- 你不知道的5个HTML5新功能(第二辑)
- jquery 弹出层
- 通过JS判断联网类型和连接状态的实现代码
- html5的video详解
- 移动前端自适应解决方案和比较
- html5视频播放解决方案
- 剑指offer--17.合并两个排序的链表