yyl说是用链表O(n)做

但是并脑补不出来。

发现可以用个vector记录一下每个数出现的位置,然后对于每个新序列就二分一下,找下一个数出现的离当前位置最近的位置,更新一下当前位置即可。

时间复杂度O(∑ k log k)的,不用卡常也过了。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N=;
vector<int> vec[N];
int a[N],b[N],n,m,k,nxt[N];
bool ck(){
scanf("%d",&k);
int pos=;
for(int i=;i<=k;i++) scanf("%d",&b[i]),nxt[b[i]]=;
for(int i=;i<=k;i++) {
nxt[b[i]]=upper_bound(vec[b[i]].begin(),vec[b[i]].end(),pos)-vec[b[i]].begin();
if(nxt[b[i]]==vec[b[i]].size()) return ;
pos=vec[b[i]][nxt[b[i]]];
}
return ;
}
int main() {
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]),vec[a[i]].push_back(i);
scanf("%d",&m);
for(int i=;i<=m;i++) puts(ck()?"TAK":"NIE");
return ;
}

Intelligence test

[POI2010] Intelligence test的更多相关文章

  1. BZOJ2083: [Poi2010]Intelligence test

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

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

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

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

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

  4. BZOJ 2083: [Poi2010]Intelligence test

    Description 问一个序列是不是起始序列的子序列. Sol 二分. 直接维护每个数出现的位置,二分一个最小的就行. Code /******************************** ...

  5. bzoj2083: [Poi2010]Intelligence test(二分+vector)

    只是记录一下vector的用法 v.push_back(x)加入x v.pop_back()弹出最后一个元素 v[x]=v.back(),v.pop_back()删除x,但是会打乱vector顺序 v ...

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

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

  7. 【二分】bzoj2083 [Poi2010]Intelligence test

    v[x]记录了x值的出现位置序列. 对每个b中的元素,每次在v[b[i]]中二分. 因此要记录上一次二分到了a数组的哪个位置. #include<cstdio> #include<v ...

  8. 【bzoj2083】[Poi2010]Intelligence test STL-vector+二分查找

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

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

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

随机推荐

  1. gradle配置国内的镜像

    gradle配置国内的镜像 学习了:http://blog.csdn.net/stdupanda/article/details/72724181 http://blog.csdn.net/lj402 ...

  2. [RxJS] Throttling vs Debouncing

    DebounceTime: It's like delay, but passes only the most recent value from each burst of emissions. T ...

  3. WEB开发面试题

    1.HTML的全称:   2.HTML的结构:   3.经常使用标签:                   4.CSS的全称: 5.CSS的作用:   6.CSS中创建Class的语法:        ...

  4. luogu3834 【模板】可持久化线段树1(主席树)

    关键字:线段树 可持久化 线段树:当版本(即对应的原序列的区间[1,r])一定时,每个节点的left,right下标为值域,值为其对应的原序列区间[1,r]中元素大小在值域中的元素个数. 可持久化:新 ...

  5. spring:利用Spring AOP 使日志输入与方法分离

    对方法进行日志输出是一种很常见的功能.传统的做法是把输出语句写在方法体的内部,在调用该方法时,用输入语句输出信息来记录方法的执行! 1.先写一个普通类: package com.importnew; ...

  6. 2017 Multi-University Training Contest - Team 2 &&hdu 6053 TrickGCD

    TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  7. PCB MS SQL跨库执行SQL 获取返回值

    一.SQL跨库执行SQL 获取返回值 ) DECLARE @sql nvarchar(MAX) DECLARE @layer INT SET @Dblink = 'P2.fp_db.dbo.' sel ...

  8. php获得本机ipv4地址

    if (isset($_ENV["HOSTNAME"])) $MachineName = $_ENV["HOSTNAME"]; else if (isset($ ...

  9. Centos6系列安装nginx

    设置ssh服务为开机启动 输入命令:chkconfig sshd on 即可.注:若是chkconfig sshd off则禁止SSH开机启动 设定账号为bizuser ,密码为123456 第一步: ...

  10. Django中关于MySQL的bug总结

    bug one: You are trying to add a non-nullable field 'height' to person without a default; we can't d ...