CF313B.Ilya and Queries

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.

You've got string s = _s_1_s_2... s__n (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers l__i, r__i (1 ≤ l__i < r__i ≤ n). The answer to the query l__i, r__i is the number of such integers i (l__i ≤ i < r__i), that s__i = s__i + 1.

Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.

狮子伊利亚想帮助他所有的朋友通过考试。他们需要解决以下问题才能通过信息技术考试。

给定一个字符串 s=s1s2…sns = s_1 s_2 \dots s_n(nn 为字符串长度),该字符串仅由字符 . 和 # 组成,以及 mm 个查询。每个查询由一对整数 li, ril_i,\, r_i 描述(满足 1≤li<ri≤n1 \leq l_i < r_i \leq n)。对于查询 li, ril_i,\, r_i,其答案为满足 li≤i<ril_i \leq i < r_i 且 si=si+1s_i = s_{i+1} 的整数 ii 的个数。

狮子伊利亚想帮助他的朋友们,但谁来帮他呢?请帮助伊利亚解决这个问题。

输入格式

The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#".

The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers l__i, r__i (1 ≤ l__i < r__i ≤ n).

第一行包含一个长度为 nn 的字符串 ss(2≤n≤1052 \leq n \leq 10^5)。保证该字符串仅由字符 “.” 和 “#” 组成。

第二行包含一个整数 mm(1≤m≤1051 \leq m \leq 10^5)—— 查询的个数。接下来的 mm 行,每行描述一个对应的查询。第 ii 行包含两个整数 lil_i、rir_i(1≤li<ri≤n1 \leq l_i < r_i \leq n)。

输出格式

Print m integers — the answers to the queries in the order in which they are given in the input.

输出 m 个整数——即按输入中给出的顺序,各查询对应的答案。

输入输出样例

  • 输入#1

    ......
    4
    3 4
    2 3
    1 6
    2 6

    输出#1

    1
    1
    5
    4
  • 输入#2

    #..###
    5
    1 3
    5 6
    1 5
    3 6
    3 4

    输出#2

    1
    1
    2
    2
    0

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

首页