#SP0000240. Đếm nguyên tố trên đoạn có cập nhật (Counting Primes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm nguyên tố trên đoạn có cập nhật (Counting Primes)
Counting Primes
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers, indexed from to . Perform operations in their given order:
0 l r v: assign the same value to every entry . This operation replaces values; it does not add .1 l r: count the entries in the inclusive range whose current values are prime.
A prime is an integer greater than with no positive divisors other than and itself. All earlier assignments affect subsequent queries.
Input
- The first line contains two integers .
- The second line contains exactly integers .
- Each of the following lines is
0 l r vor1 l r, with .
Output
For each operation 1 l r, print on its own line the number of prime-valued entries in at that moment. Assignment operations produce no output.
Subtasks
-
Subtask 1 (20 points): ; ; ; assignment value ; every query satisfies .
-
Subtask 2 (30 points): ; ; ; assignment value ; every query satisfies .
-
Subtask 3 (50 points): ; ; ; assignment value ; every query satisfies .
Examples
Input
5 3
78 2 13 12 3
1 1 2
0 4 4 5
1 1 5
Output
1
4
Explanation
Initially the array is . Query 1 1 2 examines (composite) and (prime), so the first answer is 1. Assignment 0 4 4 5 changes only position from to , producing ; it prints nothing. Query 1 1 5 now sees four prime-valued entries (, , , and ), so the second answer is 4.