传送门

Luogu

解题思路

发现一个性质:

对于排列的任何一个循环位移,排列中的同一个数的前驱肯定是不变的。

而且,如果一个排列的循环位移是某一个区间的子序列,那么这个循环位移的结尾的 \(n-1\) 级前驱一定要位于这个区间内。

到这里我们就可以倍增维护 \(2^k\) 级祖先,然后再搞一个数据结构维护一下区间最大值就好了。

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} const int _ = 200010; int n, m, q, p[_], pre[_], lg[_];
int a[_], las[_], f[22][_], st[22][_]; inline int query(int ql, int qr) {
int x = lg[qr - ql + 1];
return max(st[x][ql], st[x][qr - (1 << x) + 1]);
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(m), read(q);
for (rg int i = 2; i <= max(n, m); ++i) lg[i] = lg[i / 2] + 1;
for (rg int i = 1; i <= n; ++i) read(p[i]); p[0] = p[n];
for (rg int i = 1; i <= m; ++i) read(a[i]);
for (rg int i = 1; i <= n; ++i) pre[p[i]] = p[i - 1];
for (rg int i = 1; i <= m; ++i) f[0][i] = las[pre[a[i]]], las[a[i]] = i;
for (rg int j = 1; j <= lg[m]; ++j)
for (rg int i = 1; i <= m; ++i)
f[j][i] = f[j - 1][f[j - 1][i]];
for (rg int i = 1; i <= m; ++i) {
st[0][i] = i;
for (rg int j = 0; j <= lg[n]; ++j)
if ((n - 1) & (1 << j)) st[0][i] = f[j][st[0][i]];
}
for (rg int j = 1; j <= lg[m]; ++j)
for (rg int i = 1; i + (1 << j) - 1 <= m; ++i)
st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
for (rg int ql, qr, i = 1; i <= q; ++i)
read(ql), read(qr), putchar(query(ql ,qr) >= ql ? '1' : '0');
return 0;
}

完结撒花 \(qwq\)

「CF1142B」Lynyrd Skynyrd的更多相关文章

  1. 【CF1142B】Lynyrd Skynyrd

    [CF1142B]Lynyrd Skynyrd 题面 洛谷 题解 假设区间\([l,r]\)内有一个循环位移,那么这个循环位移一定有一个最后的点,而这个点在循环位移中再往前移\(n-1\)个位置也一定 ...

  2. 【题解】CF1142B Lynyrd Skynyrd(倍增)

    [题解]CF1142B Lynyrd Skynyrd(倍增) 调了一个小时原来是读入读反了.... 求子段是否存在一个排列的子序列的套路是把给定排列看做置换,然后让给定的序列乘上这个置换,问题就转化为 ...

  3. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  4. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  5. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  6. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  7. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  8. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

  9. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

随机推荐

  1. JS 抖动函数封装

    原生JS实现封装的抖动函数框架 <style> ul{ margin-top: 100px; } li { float: left; margin-left: 20px; position ...

  2. layui之弹出层关闭和刷新问题

    本篇文章是根据本人实际开发的例子来讲的,不一定适用各位看官的情况 描述: 主页面,弹出第一个弹框,第一个弹框中在弹出第二个弹框,如图: 1是主页面,2是子弹窗,3是孙弹窗 功能一:好了,第一个我要实现 ...

  3. python的os库

    os库(operating system,提供操作系统函数) 1. __file__是什么? ans:当前文件的名字. 例如r.py内容如下 import os if __name__ == &quo ...

  4. fdssd

    #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #in ...

  5. kafka高吞吐,低延迟的分布式消息队列

    核心概念 broker是kafka的节点,多台broker集群就是kafka topic消息分为多个topic partition分区,topic划分了多个partition分区,存在负载均衡策略 每 ...

  6. spring 的异步处理

    1.先解析几个类的用法 1.1  java.lang.annotation.Annotation @Target(ElementType.FIELD) @Retention(RetentionPoli ...

  7. Python 多任务(线程) day1

    多任务就是可以让一台电脑同时执行多个命令. 以前的单核cpu是怎么做到同时执行多个命令的?(时间片轮转) ——其实以前的单核CPU是让操作系统交替执行命令,每个任务执行0.01秒,这样看起来就像是在同 ...

  8. Spring - Spring 常用注解

    概述 简单整理一些 Spring 的注解 这个算是一个 水一波 类型的整理 内容不全 分类可能有的地方不会太符合逻辑 而且时间也不太充裕 先把自己想写的写下来, 然后随缘整理吧 约定 版本 Sprin ...

  9. IOS上给body和html绑定click事件的坑

    场景: 在ios上(包括iPhone和ipad) 给window ,html,document,body绑定click事件,点击不会触发 由于ios浏览器都用的safari内核,所以ios浏览器全部中 ...

  10. Go 后端主要做什么

    漫谈 Go 语言后端开发 :https://blog.csdn.net/u010986776/article/details/87276303 Golang 资深后端工程师要了解的知识:https:/ ...