PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000242. Truy vấn số nguyên tố trên dãy (Prime queries)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn non-negative integers a1,…,ana_1,\ldots,a_n, indexed from 11. Process qq operations in their given order:

  • A V l: add VV to ala_l.
  • R a l r: assign the value aa to all elements from ala_l to ara_r; do not add aa.
  • Q l r: count indices i∈[l,r]i\in[l,r] for which the current aia_i is prime and at most 10710^7.

A prime is an integer greater than 11 having exactly two positive divisors. A prime greater than 10710^7 does not count towards the answer. Every query reflects all previous updates.

Input

  • The first line contains integers n,qn,q.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.
  • Each of the next qq lines is A V l, R a l r, or Q 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): 1≤n≤251\le n\le25; 1≤q≤401\le q\le40; 0≤ai≤10000\le a_i\le1000; 0≤V≤2000\le V\le200; 0≤a≤2000\le a\le200; valid one-based indices, inclusive ranges 1≤l≤r≤n1\le l\le r\le n; all array values remain in [0,109][0,10^9].

  • Subtask 2 (30 points): 1≤n≤30001\le n\le3000; 1≤q≤50001\le q\le5000; 0≤ai≤1060\le a_i\le10^6; 0≤V≤1030\le V\le10^3; 0≤a≤1060\le a\le10^6; valid one-based indices, inclusive ranges 1≤l≤r≤n1\le l\le r\le n; all array values remain in [0,109][0,10^9].

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤q≤1051\le q\le10^5; 0≤ai≤1080\le a_i\le10^8; 0≤V≤1030\le V\le10^3; 0≤a≤1070\le a\le10^7; valid one-based indices, inclusive ranges 1≤l≤r≤n1\le l\le r\le n; all array values remain in [0,109][0,10^9].

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 [1,2,3,4,5][1,2,3,4,5]. Operation A 3 1 makes it [4,2,3,4,5][4,2,3,4,5], and Q 1 3 counts 2,32,3, yielding 2. R 5 2 4 assigns 55 to positions 22 through 44, producing [4,5,5,5,5][4,5,5,5,5]. Adding 11 at position 11 produces five copies of 55; the next three queries yield 1, 2, and 4. Finally A 3 5 changes the last entry to 88, so Q 5 5 returns 0 and Q 1 5 returns 4.