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

Aladin

Diamond II 다이아몬드 II
난이도
8s
시간 제한
64MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

Aladin was walking down the path one day when he found the strangest thing: \(N\) empty boxes right next to a weird alien machine. After a bit of fumbling around he got the machine to do something.

The machine now accepts \(4\) integers \(L\), \(R\), \(A\) and \(B\). After that, hitting the big red glowing button labeled "NE DIRAJ" causes the machine to go crazy and follow the next routine:

  • Set the number of stones in the box labeled \(L\) to \(A \bmod B\).
  • It proceeds to fly to the box labeled \(L+1\), and sets the number of stones there to \((2 \cdot A) \bmod B\).
  • It proceeds to fly to the box labeled \(L+2\), and sets the number of stones there to \((3 \cdot A) \bmod B\).
  • Generally, it visits each box labeled between \(L\) and \(R\), and sets the number of stones there to \(\big((X - L + 1) \cdot A\big) \bmod B\), where \(X\) is the box label.
  • After it visits the box labeled \(R\), it settles down for further instructions.

During the game Aladin wonders what is the total number of stones in some range of boxes. Write a program that simulates the device and answers Aladin's questions.

제약

Test cases worth 30% total points have N and \(Q \le 1000\).
Test cases worth 70% total points have \(Q \le 1000\).

입력 형식

The first line contains two integers \(N\) and \(Q\) (\(1 \le N \le 1\,000\,000\,000\), \(1 \le Q \le 50\,000\)), the number of boxes and the number of queries.

The next \(Q\) lines contain information about the simulation.

  • If a line starts with \(1\), it has the format 1 L R A B (\(1 \le L \le R \le N\), \(1 \le A, B \le 1\,000\,000\)), meaning that Aladin keyed the numbers \(L\), \(R\), \(A\) and \(B\) into the device and allowed the device to do its job.
  • If a line starts with \(2\), it has the format 2 L R (\(1 \le L \le R \le N\)), meaning that Aladin wonders how many stones in total are in the boxes labeled \(L\) to \(R\), inclusive.
출력 형식

For each query beginning with \(2\), output the answer to that particular query. Queries should be processed in the order they are given in the input.

Scoring: Test cases worth \(30\%\) of total points have \(N, Q \le 1000\). Test cases worth \(70\%\) of total points have \(Q \le 1000\).

First sample description: the boxes start as \(\{0, 0, 0, 0, 0, 0\}\)\(0\) stones in total. The device sets them to \(\{1 \bmod 2, 2 \bmod 2, 3 \bmod 2, 4 \bmod 2, 5 \bmod 2, 0\} = \{1, 0, 1, 0, 1, 0\}\), or \(3\) stones in total.

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

Subtask 1

39점

\(N, Q \le 1000\)

Subtask 2

52점

\(Q \le 1000\)

Subtask 3

39점

No additional constraints (\(N \le 10^9\), \(Q \le 50\,000\)).

예제 1
입력
6 3
2 1 6
1 1 5 1 2
2 1 6
출력
0
3
예제 2
입력
4 5
1 1 4 3 4
2 1 1
2 2 2
2 3 3
2 4 4
출력
3
2
1
0
예제 3
입력
4 4
1 1 4 7 9
2 1 4
1 1 4 1 1
2 1 4
출력
16
0
문제 정보

riseoj 작성

출처 COCI 2009/2010 Contest 1

평가 및 의견

Aladin

개요
출제자 난이도 Diamond II 다이아몬드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Aladin

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