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 a of length n and an array of symbols b of length n, consisting of symbols '*' and '/'.
Let's denote a path of calculations for a segment [l;r] (1≤l≤r≤n) in the following way:
- Let x=1 initially. For every i from l to r we will consequently do the following: if bi= '*', x=x∗ai, and if bi= '/', then x=aix. Let's call a path of calculations for the segment [l;r] a list of all x that we got during the calculations (the number of them is exactly r−l+1).
For example, let a=[7, 12, 3, 5, 4, 10, 9], b=[/, ∗, /, /, /, ∗, ∗], l=2, r=6, then the path of calculations for that segment is [12, 4, 0.8, 0.2, 2].
Let's call a segment [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] (1≤l≤r≤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!
库济亚开始上学了。他得到了一份数学作业,其中给了一个长度为 n 的数组 a 和一个长度为 n 的符号数组 b,其中 b 仅由字符 * 和 / 组成。
我们定义区间 [l;r](1≤l≤r≤n)的计算路径如下:
- 初始令 x=1;
- 对每个 i 从 l 到 r 依次执行:若 bi=
*,则令 x=x×ai;若 bi=/,则令 x=aix。 - 将该过程中每一步得到的 x 值按顺序组成的列表称为区间 [l;r] 的计算路径(其长度恰好为 r−l+1)。
例如,设 a=[7, 12, 3, 5, 4, 10, 9],b=[/, ∗, /, /, /, ∗, ∗],且 l=2,r=6,则该区间的计算路径为 [12, 4, 0.8, 0.2, 2]。
若一个区间 [l;r] 的计算路径中所有数值均为整数,则称该区间为简单区间。
库济亚需要找出所有满足 1≤l≤r≤n 的简单区间 [l;r] 的个数。显然,他既没时间也没兴趣手动枚举并验证每一个可能的区间,因此请你编写一个程序来求出这个数目!
输入格式
The first line contains a single integer n (2≤n≤106).
The second line contains n integers a1,a2,…,an (1≤ai≤106).
The third line contains n symbols without spaces between them — the array b1,b2…bn (bi= '/' or bi= '*' for every 1≤i≤n).
第一行包含一个整数 n(2≤n≤106)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤106)。
第三行包含 n 个无空格分隔的符号——数组 b1,b2,…,bn(对每个 1≤i≤n,有 bi= '/' 或 bi= '*')。
输出格式
Print a single integer — the number of simple segments [l;r].
输出一个整数——简单区间 [l;r] 的数量。
输入输出样例
输入#1
3 1 2 3 */*
输出#1
2
输入#2
7 6 4 10 1 2 15 1 */*/*//
输出#2
8
输入解题思路,AI测评打分。不知道怎么写?