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:

  1. 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.
  2. 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+1n+1 座城市组成,这些城市沿一条笔直的高速公路依次排列。我们按它们在高速公路上出现的顺序,用连续整数 11 到 n+1n+1 对这些城市编号。因此,这些城市由 nn 段高速公路连接,其中第 ii 段高速公路连接第 ii 号城市与第 i+1i+1 号城市。每一段高速公路均关联一个正整数 ai>1a_i > 1 —— 即该路段发生交通拥堵的周期。

为从城市 xx 到达城市 yy(其中 x<yx < y),部分司机采用如下策略:

初始时,司机位于城市 xx,当前时间 tt 为 00。在司机抵达城市 yy 前,他反复执行以下操作:

  • 若当前时间 tt 是 axa_x 的倍数,则第 xx 号高速公路路段当前正发生交通拥堵,司机在当前城市停留一单位时间(形式化地,令 t=t+1t = t + 1);
  • 若当前时间 tt 不是 axa_x 的倍数,则第 xx 号高速公路路段当前畅通,司机花费一单位时间驶向城市 x+1x+1(形式化地,令 t=t+1t = t + 1 且 x=x+1x = x + 1)。

你正在开发一套新型交通控制系统。你需要依次处理 qq 个查询,查询分为两类:

  1. 计算从城市 xx 到城市 yy(其中 x<yx < y)按上述策略行驶后最终的时间 tt 值。注意:对每个查询,tt 均重置为 00。
  2. 将第 xx 号高速公路路段的交通拥堵周期更新为 yy(形式化地,令 ax=ya_x = 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.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)——表示连接 n+1n+1 座城市的高速公路路段数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(2≤ai≤62 \leq a_i \leq 6)——表示各高速公路路段上交通拥堵出现的周期。

接下来一行包含一个整数 qq(1≤q≤1051 \leq q \leq 10^5)——表示需要处理的查询数量。

接下来 qq 行,每行描述一个查询,格式为 cc, xx, yy(其中 cc 为查询类型)。

若 cc 是字符 'A',则需处理第一类查询。此时满足约束:1≤x<y≤n+11 \leq x < y \leq n+1。

若 cc 是字符 'C',则需处理第二类查询。此时满足约束:1≤x≤n1 \leq x \leq n,2≤y≤62 \leq y \leq 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.

对于每个第一类查询,输出一个整数——从城市 xx 驾车前往城市 yy 后的最终时间 tt。请按照输入中给出的顺序处理查询。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页