RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00137

Program

Platinum III 플래티넘 III
난이도
5s
시간 제한
32MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Mirko is trying to debug a piece of his code. First he creates an array of \(N\) integers and fills it with zeros. Then he repeatedly calls the following procedure (he is such a good coder he coded it in both C++ and Pascal):

void something( int jump ) {
    int i = 0;
    while( i < N ) {
        seq[i] = seq[i] + 1;
        i = i + jump;
    }
}
procedure something( jump: longint );
var i : longint;
begin
    i := 0;
    while i < N do
    begin
        seq[i] := seq[i] + 1;
        i := i + jump;
    end;
end;

As you can see, this procedure increases by one all elements in the array whose indices are divisible by jump.

Mirko calls the procedure exactly \(K\) times, using the sequence \(X_1\ X_2\ X_3 \ldots X_K\) as arguments.

After this, Mirko has a list of \(Q\) special parts of the array he needs to check to verify that his code is working as it should be. Each of these parts is defined by two numbers, \(L\) and \(R\) (\(L \le R\)), the left and right bound of the special part. To check the code, Mirko must compute the sum of all elements of seq between and including \(L\) and \(R\). In other words \(\text{seq}[L] + \text{seq}[L+1] + \text{seq}[L+2] + \ldots + \text{seq}[R]\). Since he needs to know the answer in advance in order to check it, he asked you to help him.

제약
입력 형식

The first line of input contains two integers, \(N\) (\(1 \le N \le 10^6\)), size of the array, and \(K\) (\(1 \le K \le 10^6\)), number of calls to something Mirko makes.

The second line contains \(K\) integers: \(X_1\ X_2\ X_3 \ldots X_K\), arguments passed to the procedure (\(1 \le X_i < N\)).

The next line contains one integer \(Q\) (\(1 \le Q \le 10^6\)), number of special parts of the array Mirko needs to check.

The next \(Q\) lines contain two integers each, \(L_i\) and \(R_i\) (\(0 \le L_i \le R_i < N\)), bounds of each special part.

출력 형식

The output should contain exactly \(Q\) lines. The \(i\)-th line should contain the sum of elements \(\text{seq}[L_i] + \text{seq}[L_i+1] + \text{seq}[L_i+2] + \ldots + \text{seq}[R_i]\).

First sample description: The procedure is called with arguments \(1, 1, 2, 1\). After that the array contains values \(\{4, 3, 4, 3, 4, 3, 4, 3, 4, 3\}\). Sum of indices \(2\) to \(6\) (inclusive) is \(4+3+4+3+4 = 18\).

Second sample description: The array is \(\{3, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1\}\).

서브태스크
서브태스크점수설명

Test 1

10점

None

Test 2

10점

None

Test 3

10점

None

Test 4

10점

None

Test 5

10점

None

Test 6

10점

None

Test 7

10점

None

Test 8

10점

None

Test 9

10점

None

Test 10

10점

None

예제 1
입력
10 4
1 1 2 1
3
0 9
2 6
7 7
출력
35
18
3
예제 2
입력
11 3
3 7 10
3
0 10
2 6
7 7
출력
8
2
1
예제 3
입력
1000000 6
12 3 21 436 2 19
2
12 16124
692 29021
출력
16422
28874
문제 정보

riseoj 작성

출처 COCI 2009/2010 Contest 5

평가 및 의견

Program

개요
출제자 난이도 Platinum III 플래티넘 III 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Program

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8