Friends and Subsequences

把 LangGraph 当“工作流引擎”用:与传统 BPM 的差异与融合策略 首先,我们来回顾一下有限状态机(FSM)的基本定义——一个 FSM 可以用一个五元组MQΣδq0FMQΣδq0​FQQQ有限状态集合,包含 FSM 所有可能的状态;Σ\SigmaΣ有限输入字母表,包含 FSM 所有可能的输入;δ\deltaδ状态转移函数,定义了 FSM 从当前状态q∈Qq \in Qq∈Q接收输入σ∈Σσ∈Σ后,转移到的下一个状态q′∈Qq' \in Qq′∈Q,即δQ×Σ→QδQ×Σ→Q。 阅读详情

Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows?

Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r), Mike can instantly tell the value of while !Mike can instantly tell the value of .

Now suppose a robot (you!) asks them all possible different queries of pairs of integers (l, r) (1 ≤ l ≤ r ≤ n) (so he will make exactly n(n + 1) / 2 queries) and counts how many times their answers coincide, thus for how many pairs is satisfied.

How many occasions will the robot count?

Input
The first line contains only integer n (1 ≤ n ≤ 200 000).

The second line contains n integer numbers a1, a2, …, an ( - 109 ≤ ai ≤ 109) — the sequence a.

The third line contains n integer numbers b1, b2, …, bn ( - 109 ≤ bi ≤ 109) — the sequence b.

Output
Print the only integer number — the number of occasions the robot will count, thus for how many pairs is satisfied.

Examples
input
6
1 2 3 2 1 4
6 7 1 2 3 2
output
2
input
3
3 3 3
1 1 1
output
0
Note
The occasions in the first sample case are:

1.l = 4,r = 4 since max{2} = min{2}.

2.l = 4,r = 5 since max{2, 1} = min{2, 3}.

There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.

本题是暴力+优化
首先想到左端点找到之后枚举右边端点
然后想到对有任何一个左端点,向右的最大或者最小值是单调的

因此开始二分

二分出的区间是同样的最大最小值

因此分两次二分
一次枚举左一次枚举右

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
long long  f[200001][30], tua[200001], fx[200001][30], tub[200001], ty[200001];
long long  n, m;
void rmq(long long c)
{
    long long cc = 20;
    for (long long a = 1; a <= cc; a++)
    {
        for (long long b = 1; b <= c; b++)
        {
            if (b + (1 << a) - 1 <= c)
            {
                f[b][a] = max(f[b][a - 1], f[b + (1 << (a - 1))][a - 1]);
                fx[b][a] = min(fx[b][a - 1], fx[b + (1 << (a - 1))][a - 1]);
            }
        }
    }
}
long long xunwenda(long long zuo, long long you)
{
    long long k = log2(you - zuo + 1);
    return max(f[zuo][k], f[you - (1 << k) + 1][k]);
}
long long xunwenxiao(long long zuo, long long you)
{
    long long k = log2(you - zuo + 1);
    return min(fx[zuo][k], fx[you - (1 << k) + 1][k]);
}
long long jc(long long z, long long y)
{
    if (xunwenda(z, y) > xunwenxiao(z, y))return 0;
    else if (xunwenda(z, y) == xunwenxiao(z, y))return 1;
    return 2;
}
int main()
{
#define int long long
    int n;
    cin >> n;
    for (int a = 1; a <= n; a++)scanf("%lld", &tua[a]);
    for (int a = 1; a <= n; a++)scanf("%lld", &tub[a]);
    for (int a = 1; a <= n; a++)f[a][0] = tua[a];
    for (int a = 1; a <= n; a++)fx[a][0] = tub[a];
    rmq(n);
    int qw = 0;
    for (int a = 1; a <= n; a++)
    {
        int z = a, y = n;
        int tt = 0;
        while (z <= y)
        {
            int mid = (z + y) / 2;
            int qq = jc(a, mid);
            if (qq == 1)
            {
                tt = max(tt, mid);
            }
            if (qq == 0)
            {
                y = mid - 1;
            }
            else
            {
                z = mid + 1;
            }
        }
        ty[a] += tt;
    }
    for (int a = 1; a <= n; a++)
    {
        int z = a, y = n;
        int tt = 2100000;
        while (z <= y)
        {
            int mid = (z + y) / 2;
            int qq = jc(a, mid);
            if (qq == 1)
            {
                tt = min(tt, mid);
            }
            if (qq == 0 || qq == 1)
            {
                y = mid - 1;
            }
            else if (qq == 2)
            {
                z = mid + 1;
            }
        }
        ty[a] -= tt;
    }
    for (int a = 1; a <= n; a++)
    {
        if (ty[a] < 0)continue;
        qw += ty[a]+1;
    }
    cout << qw;
}
《QEMU/KVM源码分析与应用》读书笔记4 —— 第2章 QEMU基本组件(1) 阅读详情

相关推荐

从零构建腾讯滑块验证码破解引擎:逆向工程与实战对抗

本文深入解析腾讯滑块验证码(原天御验证码)的防护机制,包括环境感知层、行为分析层和验证决策层的核心技术。通过JSVMP虚拟机保护、轨迹验证算法和动态加密体系,腾讯验证码实现了高效的人机识别。文章还提供了安全研究实践指南,涵盖环境模拟和验证码识别方案,并探讨了防御对抗的演进趋势与合规研究建议。

rl6adventurer的博客 844

Codeforces - Friends and Subsequences

题目链接:Codeforces - Friends and Subsequences 很显然max和min的前缀和具有单调性。 所以我们枚举左端点,二分右端点即可。 AC代码: #pragma GCC optimize("-Ofast","-funroll-all-loops") #include<bits/stdc++.h> //#define int long long usin...

青烟绕指柔的博客 506

vasp-自旋轨道耦合(SOC)计算步骤

在VASP中执行自旋轨道耦合(SOC)计算,具体的计算步骤如下: 结构优化获取CONTCAR文件 自洽计算(collinear normal VASP calculations)获取IBZKPT,CHGCAR和WAVECAR文件。 SCF+SOC计算,在此步骤中,将步骤2中的IBZKPT复制为KPOINTS,以便两个步骤具有相同的k网格,因此可以读取步骤2中的CHGCAR和WAVECAR文件。 能带结构计算,在此步骤中,将KPOINTS改为高对称点,读取步骤3中的CHGCAR和WAVECAR文件。

懒散的鱼与消失的猫 3万+

[Codeforces 689D] Friends and Subsequences (二分+稀疏表)

Codeforces - 689D 给定两个序列 AA,BB,求问有多少个区间 [l,r][l,r]满足 max(A[l,r])=min(B[l,r])max(A[l,r]) = min(B[l,r]) 考虑枚举区间左端点,移动右端点的过程中 max(A[l,r])max(A[l,r])肯定越来越大,min(B[l,r])min(B[l,r])越来越小 用 d=max(A[l,r])−

MisDeer's blog 710

从12摄像头到纯视觉:小鹏AI鹰眼方案如何用LOFIC技术省掉激光雷达?

本文深入解析小鹏汽车AI鹰眼方案如何通过LOFIC技术实现纯视觉自动驾驶,替代传统激光雷达。LOFIC摄像头在动态范围、噪声控制和HDR优化方面表现卓越,结合800万像素双目广角摄像头,达到激光雷达级测距精度。该方案不仅降低成本,还提升系统可靠性和用户体验,展示了纯视觉路线的技术潜力与边界。

t8u9v0w1x的博客 957

ComfyUI-controlnet控制出图

提供加载预处理器节点。

Bu2n的博客 5513

【CodeForces - 689D】Friends and Subsequences(RMQ,二分 或单调队列)

题干: Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you)— who knows...

xuanweiace的博客 516

破解现代反爬虫:JS加密、OB混淆与CSS反爬的实战攻防分析

摘要: 随着反爬技术的升级,JS加密、OB混淆和CSS反爬成为主流防护手段,阻碍传统爬虫获取数据。本文解析了这些技术的工作原理,并提出破解策略:通过模拟浏览器(如Selenium、Puppeteer)执行动态JS,逆向混淆代码,以及利用开发者工具突破CSS隐藏。针对复杂防护,开发者需结合技术分析与工具应用,如API接口抓取、动态渲染破解等,以应对不断演进的反爬机制。未来,爬虫攻防将持续升级,需保持技术敏锐性。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1665

Codeforces 689 D - Friends and Subsequences(数据结构 RMQ +二分)

题目链接 看过来 题意 给定两个长度为nnn的数列a,ba,ba,b,问有多少个区间[L,R](0≤L≤R&amp;lt;n)[L,R](0≤L≤R&amp;lt;n)[L,R] (0\leq L \leq Rmax(al,al+1,...,ar)=min(bl,bl+1,...,br)max(al,al+1,...,ar)=min(bl,bl+1,...,br)max(a_l,a_{l+1},.....

MasterAn的博客 396

【Claude】Not logged in 错误:未登录状态的判断与 /login 认证路径 bug报错已解决

login 是首选修复:大多数 "Not logged in" 只需重新执行 /login检查系统时间:时间偏差是 Token 验证失败的常见原因避免密钥库被清理:将 Claude Code 添加到系统清理工具的白名单企业环境用 API Key:如果组织禁用 OAuth,使用 API Key 认证区分凭证类型:理解 Not logged in(无凭证)vs Invalid key(有但无效)

博客 7359

AutoSAR从0开始实战 --- 目录

​​​​​​本专栏是全网最真实的AutoSAR实战专栏,博主将从一个0基础小白的身份来讲解AutoSAR工具的配置,以及相应代码的讲解。

wj博客 1742

CF689D Friends and Subsequences(ST表+二分)

题目传送门 题意 给定序列 aaa 和序列 bbb,长度均为 nnn。问有多少组 (l,r)(l,r)(l,r),满足 1≤l≤r≤n1\le l\le r\le n1≤l≤r≤n 且 max⁡i=lrai=min⁡i=lrbi\max_{i=l}^r a_i=\min_{i=l}^r b_ii=lmaxr​ai​=i=lminr​bi​ 1≤n≤2×1051\le n\le 2\times 10^51≤n≤2×105,∣ai∣,∣bi∣≤109|a_i|,|b_i|\le 10^9∣ai​∣,∣bi​∣

m0_51841071的博客 482

Visual Studio调试技巧与实用方法总结(实战经验分享)

本文根据多年的项目实战经验,详细介绍一些Visual Studio常用的高效调试手段与技巧。

dvlinker的技术专栏 3万+

CodeForces 689D-Friends and Subsequences

题目链接:http://codeforces.com/contest/689/problem/D 原题: Description:Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they c

qq_29081867的博客 295

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

CodeForces 689 D Friends and Subsequences

Friends and Subsequences 题解: 如果左端点来说, 那么对于a[i]来说是向上的一条折线, b[i]来说是向下的一条折线, 那么如果这2个折线求交点个数的话, 我们可以二分去求第一个 a[i] == b[i] 的地方, 求最后一个a[i] == b[i]的地方。 代码: #include<bits/stdc++.h> using...

dengpangbu3703的博客 154

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

CF689D Friends and Subsequences

题目大意 给出两个长度为 nnn 的序列 aaa 和 bbb,计算有多少对 l,rl,rl,r 满足 max⁡{al,al+1,…,ar−1,ar}=min⁡{bl,bl+1,…,br−1,br}\max\{a_l,a_{l+1},\dots,a_{r-1},a_r\}=\min\{b_l,b_{l+1},\dots,b_{r-1},b_r\}max{al​,al+1​,…,ar−1​,ar​}=...

sxy__orz的博客 206

Codeforces Round #361 (Div. 2) D. Friends and Subsequences 二分

D. Friends and Subsequences 题目连接: http://www.codeforces.com/contest/689/problem/D Description Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Toda...

weixin_30856965的博客 93

C - Friends and Subsequences

Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows...

weixin_30677073的博客 145

codeforces 689 D. Friends and Subsequences

ST 表 + 二分

m0_69735030的博客 182

Friends and Subsequences CodeForces - 689D

http://codeforces.com/problemset/problem/689/D 分别对a和b维护最大和最小rmq 枚举左端点 右端点满足单调性 二分找第一个和最后一个使a和b区间最值相等的点即为右端点 #include &lt;bits/stdc++.h&gt; using namespace std; #define ll long long int a[200010][2...

sunyutian1998的博客 304

CF 689D - Friends and Subsequences

689D - Friends and Subsequences 题意: 大致跟之前题目一样,用ST表维护a[]区间max,b[]区间min,找出多少对(l,r)使得maxa(l,r) == minb(l,r) 切题的感觉很爽唉 同样而二分查找,找最小和最大下标满足条件 cf中%I64d, 一般是%lld 代码: #include<bits/stdc++.h> #define ll ...

weixin_34310127的博客 219
上一篇: Mike and Chocolate Thieves
下一篇: CodeForces - 735C
NineFailure
博客等级 码龄11年 22粉丝 317原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值