#SP0000242. Truy vấn số nguyên tố trên dãy (Prime queries)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn số nguyên tố trên dãy (Prime queries)
Prime queries
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of non-negative integers , indexed from . Process operations in their given order:
A V l: add to .R a l r: assign the value to all elements from to ; do not add .Q l r: count indices for which the current is prime and at most .
A prime is an integer greater than having exactly two positive divisors. A prime greater than does not count towards the answer. Every query reflects all previous updates.
Input
- The first line contains integers .
- The second line contains exactly integers .
- Each of the next lines is
A V l,R a l r, orQ l r. Array indices are one-based.
Output
For each Q l r operation, print the requested count on a separate line. Update operations produce no output.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; ; valid one-based indices, inclusive ranges ; all array values remain in .
-
Subtask 2 (30 points): ; ; ; ; ; valid one-based indices, inclusive ranges ; all array values remain in .
-
Subtask 3 (50 points): ; ; ; ; ; valid one-based indices, inclusive ranges ; all array values remain in .
Examples
Input
5 10
1 2 3 4 5
A 3 1
Q 1 3
R 5 2 4
A 1 1
Q 1 1
Q 1 2
Q 1 4
A 3 5
Q 5 5
Q 1 5
Output
2
1
2
4
0
4
Explanation
Initially the array is . Operation A 3 1 makes it , and Q 1 3 counts , yielding 2. R 5 2 4 assigns to positions through , producing . Adding at position produces five copies of ; the next three queries yield 1, 2, and 4. Finally A 3 5 changes the last entry to , so Q 5 5 returns 0 and Q 1 5 returns 4.