Description

问一个序列是不是起始序列的子序列.

Sol

二分.

直接维护每个数出现的位置,二分一个最小的就行.

Code

/**************************************************************
Problem: 2083
User: BeiYu
Language: C++
Result: Accepted
Time:7024 ms
Memory:34132 kb
****************************************************************/ #include <bits/stdc++.h>
using namespace std; #define debug(a) cout<<#a<<"="<<a<<" "
const int N = 1e6+50; int n;
vector< int > a[N]; inline int in(int x=0,char ch=getchar()) { while(ch>'9' || ch<'0') ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x; }
int main() {
n=in();
for(int i=1,x;i<=n;i++) x=in(),a[x].push_back(i);
for(int i=1;i<N;i++) a[i].push_back(n+1);
for(int T=in();T--;) {
int m=in(),pos=0,f=0;vector< int > :: iterator it;
for(int i=1,x;i<=m;i++) {
x=in();
if(f) continue;
it=upper_bound(a[x].begin(),a[x].end(),pos);
if(*it!=n+1) pos=*it;
else f=1;
// debug(pos),debug(f)<<endl;
}
if(f) puts("NIE");
else puts("TAK");
}
return 0;
}

BZOJ 2083: [Poi2010]Intelligence test的更多相关文章

  1. BZOJ 2083: [Poi2010]Intelligence test [vector+二分]

    2083: [Poi2010]Intelligence test Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 469  Solved: 227[Su ...

  2. bzoj 2083 [Poi2010]Intelligence test——思路+vector/链表

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2083 给每个值开一个vector.每个询问挂在其第一个值上:然后枚举给定序列,遇到一个值就访 ...

  3. bzoj 2083: [Poi2010]Intelligence test——vecto+二分

    Description 霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.Lyx很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算 ...

  4. BZOJ2083: [Poi2010]Intelligence test

    2083: [Poi2010]Intelligence test Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 241  Solved: 96[Sub ...

  5. BZOJ 2083 vector的巧用+二分

    2083: [Poi2010]Intelligence test Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 469  Solved: 227[Su ...

  6. 【BZOJ2083】[Poi2010]Intelligence test 二分

    [BZOJ2083][Poi2010]Intelligence test Description 霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.Lyx很渴望成为霸 ...

  7. bzoj 2083 Intelligence test —— 思路+vector

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2083 先把所有子序列都存下来,总长度应该有限制,所以用 vector 存: 要做到 O(n) ...

  8. BZOJ 2083 Intelligence test

    用vector,二分. #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  9. [BZOJ 2083] [POI 2010] Intelligence test

    Description 霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.Lyx很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算 ...

随机推荐

  1. [LeetCode] Find the Celebrity 寻找名人

    Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist o ...

  2. IT培训行业揭秘(五)

    前面说了一大堆,简单揭露了一些目前培训行业鱼龙混在的情况,那么今天我就站在一个即将毕业的大学生角度来谈谈如何选择一个靠谱的培训机构. 你即将大学毕业了,在大学里面浑浑噩噩的混了几年,马上就要离开校园, ...

  3. 【java基础系列】一、常用命令行

    常用的DOS命令: dir:列出当前目录下的文件以及文件夹 md:创建目录 rd:删除目录 cd:进入指定目录 cd..:退回到上一级目录 cd\:退回到根目录 del:删除文件 exit:退出dos ...

  4. SSM整合(二):Spring4与Mybatis3整合

    上一节测试好了Mybatis3,接下来整合Spring4! 一.添加spring上下文配置 在src/main/resources/目录下的spring新建spring上下文配置文件applicati ...

  5. MySQL基础

    数据库操作 ---终端使用数据库 mysql -u root -p 之后回车键 输入密码 ---显示所有数据库: show databases; ---默认数据库: mysql - 用户权限相关数据 ...

  6. MATLAB的三维散点图

    MATLAB中三维散点图函数为scatter3(x,y,z) 三维火柴图为stem3(x,y,z)

  7. 前端神器avalonJS入门(一)

    转自:http://www.cnblogs.com/vajoy/p/4063824.html avalonJS是司徒正美开发和维护的前端mvvm框架,可以轻松实现数据的隔离和双向绑定,相比angula ...

  8. install hadoop on xubuntu

    0. install xubuntu we recommend to set username as "hadoop" after installation, set user & ...

  9. div+css:div中图片垂直居中

    div中图片垂直居中 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  10. 通过WebStorm上传代码至github

    首先需要注册github帐号,具体方法自行百度/谷歌. 打开WebStorm,我用的是2016.2.4版本(如果你有edu邮箱的话,可以免费使用一年,不只是Webstorm,JetBrains全家桶都 ...