题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2083

给每个值开一个vector。每个询问挂在其第一个值上;然后枚举给定序列,遇到一个值就访问那个值的vector,把里面的询问序列都向前推进一位,挂在新的值的vector里。

注意不要一边消一边挂,因为可能消的和挂的是同一个值;只要临时存一下就行了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e6+;
int n,m,a[N],len[N],p[N],top;
vector<int> b[N],w[N];
pair<int,int> sta[N];
int rdn()
{
int ret=;bool fx=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')fx=;ch=getchar();}
while(ch>=''&&ch<='') ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return fx?ret:-ret;
}
int main()
{
m=rdn();for(int i=;i<=m;i++)a[i]=rdn();
n=rdn();
for(int i=;i<=n;i++)
{
len[i]=rdn();
for(int j=,d;j<=len[i];j++)
d=rdn(),b[i].push_back(d);
p[i]=;
w[b[i][p[i]]].push_back(i);
}
for(int i=;i<=m;i++)
{
int d=w[a[i]].size();top=;
for(int j=d-;j>=;j--)
{
int k=w[a[i]][j];
w[a[i]].pop_back(); p[k]++;
if(p[k]==len[k])continue;
int c=b[k][p[k]];
sta[++top]=make_pair(c,k);
}
for(int i=;i<=top;i++)
w[sta[i].first].push_back(sta[i].second);
}
for(int i=;i<=n;i++)
puts(p[i]==len[i]?"TAK":"NIE");
return ;
}

最新文章

  1. git 常用命令粗略总结
  2. Spring mvc 中使用ftl引用共通文件出错 FreeMarker template error: Error reading included file &quot;/WEB-INF/ftl/common/errormessage.ftl&quot;
  3. 用ProGet搭建内部的NuGet服务器(更新安装步骤)
  4. 银行支票和汇票中使用的专用字体MICR E13B条形码控件字体
  5. 转载RabbitMQ入门(5)--主题
  6. 【转载】颜色空间-RGB、HSI、HSV、YUV、YCbCr的简介
  7. 【转】Android仿QQ截图应用测试
  8. Android 金融项目整理
  9. 账户管理命令 useradd、groupadd
  10. CentOS minimal版安装图形界面的步骤(自动获取IP)
  11. 单机Oracle+asm(11.2.0.3.0) Patch Set Update(11.2.0.3.7 )
  12. 信号量多-threaded同步Semaphore
  13. 控件编写:增强 TMEMO (一)(增加对WM_HSCROLL消息的处理)
  14. python基础教程_学习笔记1:序列-1
  15. ffmpeg 频中分离 video audio 截取片断
  16. To the end
  17. CNN中的卷积核及TensorFlow中卷积的各种实现
  18. Calendar 类 案例 和 闰年的计算
  19. Mac使用Clion配置OpenGL
  20. SpringMVC+SpringJdbc+SQLServer+EasyUI增删改查

热门文章

  1. TI C66x DSP 四种内存保护问题 -之- CPU訪问corePac内部资源时的内存保护问题
  2. 1、CRM2011编程实战——清空指定页签以下的全部选项,并对页签以下的指定控件进行操作
  3. css3 - 基本选择器
  4. LoadRunner多负载产生器
  5. linux查找文件夹下的全部文件里是否含有某个字符串
  6. Spark 性能相关參数配置具体解释-shuffle篇
  7. 后台运行命令:&amp;amp;和nohup command &amp;amp; 以及关闭、查看后台任务
  8. 实现iOS7上tableView的切割线像iOS6中的效果
  9. Introducing Gradle (Ep 2, Android Studio)
  10. 用算法求N(N&amp;gt;=3)之内素数的个数