CF1582G.Kuzya and Homework

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kuzya started going to school. He was given math homework in which he was given an array aa of length nn and an array of symbols bb of length nn, consisting of symbols '*' and '/'.

Let's denote a path of calculations for a segment [l;r][l; r] (1≤l≤r≤n1 \le l \le r \le n) in the following way:

  • Let x=1x=1 initially. For every ii from ll to rr we will consequently do the following: if bi=b_i= '*', x=x∗aix=x*a_i, and if bi=b_i= '/', then x=xaix=\frac{x}{a_i}. Let's call a path of calculations for the segment [l;r][l; r] a list of all xx that we got during the calculations (the number of them is exactly r−l+1r - l + 1).

For example, let a=[7,a=[7, 12,12, 3,3, 5,5, 4,4, 10,10, 9]9], b=[/,b=[/, ∗,*, /,/, /,/, /,/, ∗,*, ∗]*], l=2l=2, r=6r=6, then the path of calculations for that segment is [12,[12, 4,4, 0.8,0.8, 0.2,0.2, 2]2].

Let's call a segment [l;r][l;r] simple if the path of calculations for it contains only integer numbers.

Kuzya needs to find the number of simple segments [l;r][l;r] (1≤l≤r≤n1 \le l \le r \le n). Since he obviously has no time and no interest to do the calculations for each option, he asked you to write a program to get to find that number!

库济亚开始上学了。他得到了一份数学作业,其中给了一个长度为 nn 的数组 aa 和一个长度为 nn 的符号数组 bb,其中 bb 仅由字符 * 和 / 组成。

我们定义区间 [l;r][l; r](1≤l≤r≤n1 \le l \le r \le n)的计算路径如下:

  • 初始令 x=1x = 1;
  • 对每个 ii 从 ll 到 rr 依次执行:若 bi= b_i =\,*,则令 x=x×aix = x \times a_i;若 bi= b_i =\,/,则令 x=xaix = \dfrac{x}{a_i}。
  • 将该过程中每一步得到的 xx 值按顺序组成的列表称为区间 [l;r][l; r] 的计算路径(其长度恰好为 r−l+1r - l + 1)。

例如,设 a=[7, 12, 3, 5, 4, 10, 9]a=[7,\ 12,\ 3,\ 5,\ 4,\ 10,\ 9],b=[/, ∗, /, /, /, ∗, ∗]b=[/,\ *,\ /,\ /,\ /,\ *,\ *],且 l=2l=2,r=6r=6,则该区间的计算路径为 [12, 4, 0.8, 0.2, 2][12,\ 4,\ 0.8,\ 0.2,\ 2]。

若一个区间 [l;r][l;r] 的计算路径中所有数值均为整数,则称该区间为简单区间。

库济亚需要找出所有满足 1≤l≤r≤n1 \le l \le r \le n 的简单区间 [l;r][l;r] 的个数。显然,他既没时间也没兴趣手动枚举并验证每一个可能的区间,因此请你编写一个程序来求出这个数目!

输入格式

The first line contains a single integer nn (2≤n≤1062 \le n \le 10^6).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1061 \le a_i \le 10^6).

The third line contains nn symbols without spaces between them — the array b1,b2…bnb_1, b_2 \ldots b_n (bi=b_i= '/' or bi=b_i= '*' for every 1≤i≤n1 \le i \le n).

第一行包含一个整数 nn(2≤n≤1062 \le n \le 10^6)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1061 \le a_i \le 10^6)。

第三行包含 nn 个无空格分隔的符号——数组 b1,b2,…,bnb_1, b_2, \ldots, b_n(对每个 1≤i≤n1 \le i \le n,有 bi=b_i = '/' 或 bi=b_i = '*')。

输出格式

Print a single integer — the number of simple segments [l;r][l;r].

输出一个整数——简单区间 [l;r][l;r] 的数量。

输入输出样例

  • 输入#1

    3
    1 2 3
    */*

    输出#1

    2
  • 输入#2

    7
    6 4 10 1 2 15 1
    */*/*//

    输出#2

    8

输入解题思路,AI测评打分。不知道怎么写?

首页