PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000162. Truy vấn GCD có cập nhật (GCD Queries with Updates)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Truy vấn GCD có cập nhật (GCD Queries with Updates)
GCD Queries with Updates
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain a 1-indexed array of positive integers while processing operations in order:
1 i g: Print the number of indices such that in the current array.2 i x: Permanently assign . Later queries must use the updated value.
A query of type 1 does not modify the array. Never include in the count, even if .
Input
The first line contains . The second line contains integers . Each of the next lines contains either 1 i g or 2 i x. All indices are 1-based.
Output
Print a count on a separate line for each query of type 1.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
4 4
12 8 9 18
1 1 12
1 4 2
2 2 6
1 4 6
Output
0
1
2
Explanation
Initially . No other value has GCD with , so the first answer is . Only has GCD with , so the next answer is . After assigning , the array becomes . Both and have GCD with ; does not. The final answer is .