博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷P2776 [SDOI2007]小组队列 链表 + 模拟
阅读量:4616 次
发布时间:2019-06-09

本文共 1204 字,大约阅读时间需要 4 分钟。

有些细节需要注意:

1.编号和元素种类都从0开始标号。
2.需要特判一下队列被弹空的情况。
Code:

#include
#include
using namespace std;const int maxn = 1000000 + 4;int typ[maxn], tail[maxn];int head[maxn], nex[maxn], cur[maxn], cnt, back;int main(){ // freopen("in.txt","r",stdin); int n,m, ops, pre = 1; scanf("%d%d",&n,&m); for(int i = 1;i <= n; ++i) { scanf("%d",&typ[i]); typ[i] += 1; } scanf("%d",&ops); while(ops--) { char A[10]; scanf("%s",A); if(A[1] == 'u') { int u,k; scanf("%d",&k); k += 1; u = typ[k]; if(!tail[u] || tail[u] == back) { nex[back] = ++ cnt; cur[cnt] = k; tail[u] = back = cnt; } else { nex[++cnt] = nex[tail[u]], cur[cnt] = k; nex[tail[u]] = cnt, tail[u] = cnt; } } else { printf("%d\n",cur[pre] - 1); if(typ[cur[nex[pre]]] != typ[cur[pre]] ) tail[typ[cur[pre]]] = 0; pre = nex[pre] ? nex[pre] : cnt + 1; } } return 0;}

转载于:https://www.cnblogs.com/guangheli/p/9845178.html

你可能感兴趣的文章
linux常用端口
查看>>
异常处理
查看>>
/proc/uptime详解
查看>>
如何建立合适的索引?
查看>>
acwing 651. 逛画展
查看>>
Vijos P1243 生产产品 (单调队列优化DP)
查看>>
iOS常用第三方库 -转
查看>>
Android布局学习
查看>>
python的沙盒环境--virtualenv
查看>>
软件自动化测试——入门、进阶与实战
查看>>
BZOJ1878 [SDOI2009]HH的项链 树状数组 或 莫队
查看>>
BZOJ3675 [Apio2014]序列分割 动态规划 斜率优化
查看>>
2016.10.24 继续学习
查看>>
产品功能对标 - 服务授权管理
查看>>
各地IT薪资待遇讨论
查看>>
splay入门
查看>>
带CookieContainer进行post
查看>>
C语言学习笔记--字符串
查看>>
CSS-上下文选择器
查看>>
ionic repeat 重复最后一个时要执行某个函数
查看>>