CF498D.Traffic Jams in the Land
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Some country consists of (n + 1) cities, located along a straight highway. Let's number the cities with consecutive integers from 1 to n + 1 in the order they occur along the highway. Thus, the cities are connected by n segments of the highway, the i-th segment connects cities number i and i + 1. Every segment of the highway is associated with a positive integer a__i > 1 — the period of traffic jams appearance on it.
In order to get from city x to city y (x < y), some drivers use the following tactics.
Initially the driver is in city x and the current time t equals zero. Until the driver arrives in city y, he perfors the following actions:
- if the current time t is a multiple of a__x, then the segment of the highway number x is now having traffic problems and the driver stays in the current city for one unit of time (formally speaking, we assign t = t + 1);
- if the current time t is not a multiple of a__x, then the segment of the highway number x is now clear and that's why the driver uses one unit of time to move to city x + 1 (formally, we assign t = t + 1 and x = x + 1).
You are developing a new traffic control system. You want to consecutively process q queries of two types:
- determine the final value of time t after the ride from city x to city y (x < y) assuming that we apply the tactics that is described above. Note that for each query t is being reset to 0.
- replace the period of traffic jams appearing on the segment number x by value y (formally, assign a__x = y).
Write a code that will effectively process the queries given above.
某个国家由 n+1 座城市组成,这些城市沿一条笔直的高速公路依次排列。我们按它们在高速公路上出现的顺序,用连续整数 1 到 n+1 对这些城市编号。因此,这些城市由 n 段高速公路连接,其中第 i 段高速公路连接第 i 号城市与第 i+1 号城市。每一段高速公路均关联一个正整数 ai>1 —— 即该路段发生交通拥堵的周期。
为从城市 x 到达城市 y(其中 x<y),部分司机采用如下策略:
初始时,司机位于城市 x,当前时间 t 为 0。在司机抵达城市 y 前,他反复执行以下操作:
- 若当前时间 t 是 ax 的倍数,则第 x 号高速公路路段当前正发生交通拥堵,司机在当前城市停留一单位时间(形式化地,令 t=t+1);
- 若当前时间 t 不是 ax 的倍数,则第 x 号高速公路路段当前畅通,司机花费一单位时间驶向城市 x+1(形式化地,令 t=t+1 且 x=x+1)。
你正在开发一套新型交通控制系统。你需要依次处理 q 个查询,查询分为两类:
- 计算从城市 x 到城市 y(其中 x<y)按上述策略行驶后最终的时间 t 值。注意:对每个查询,t 均重置为 0。
- 将第 x 号高速公路路段的交通拥堵周期更新为 y(形式化地,令 ax=y)。
请编写一段高效处理上述查询的代码。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of highway segments that connect the n + 1 cities.
The second line contains n integers _a_1, _a_2, ..., a__n (2 ≤ a__i ≤ 6) — the periods of traffic jams appearance on segments of the highway.
The next line contains a single integer q (1 ≤ q ≤ 105) — the number of queries to process.
The next q lines contain the descriptions of the queries in the format c, x, y (c — the query type).
If c is character 'A', then your task is to process a query of the first type. In this case the following constraints are satisfied: 1 ≤ x < y ≤ n + 1.
If c is character 'C', then you need to process a query of the second type. In such case, the following constraints are satisfied: 1 ≤ x ≤ n, 2 ≤ y ≤ 6.
第一行包含一个整数 n(1≤n≤105)——表示连接 n+1 座城市的高速公路路段数量。
第二行包含 n 个整数 a1,a2,…,an(2≤ai≤6)——表示各高速公路路段上交通拥堵出现的周期。
接下来一行包含一个整数 q(1≤q≤105)——表示需要处理的查询数量。
接下来 q 行,每行描述一个查询,格式为 c, x, y(其中 c 为查询类型)。
若 c 是字符 'A',则需处理第一类查询。此时满足约束:1≤x<y≤n+1。
若 c 是字符 'C',则需处理第二类查询。此时满足约束:1≤x≤n,2≤y≤6。
输出格式
For each query of the first type output a single integer — the final value of time t after driving from city x to city y. Process the queries in the order in which they are given in the input.
对于每个第一类查询,输出一个整数——从城市 x 驾车前往城市 y 后的最终时间 t。请按照输入中给出的顺序处理查询。
输入输出样例
输入#1
10 2 5 3 2 3 5 3 4 2 4 10 C 10 6 A 2 6 A 1 3 C 3 4 A 3 11 A 4 9 A 5 6 C 7 3 A 8 10 A 2 5
输出#1
5 3 14 6 2 4 4
输入解题思路,AI测评打分。不知道怎么写?