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

#SRD0000018. Đếm phần tử từ ngưỡng (Give Away)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm phần tử từ ngưỡng (Give Away)

Give Away

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a positive integer array a1,a2,…,ana_1,a_2,\ldots,a_n. The array changes over time. Process the following operations in their given order:

  • 0 l r c: count the indices ii in the inclusive interval [l,r][l,r] such that ai≥ca_i\ge c.
  • 1 p x: assign ap=xa_p=x. An assignment produces no output.

Every count query refers to the array after all preceding assignments.

Input

The first line contains nn, followed by nn initial array values on the next line. The next line contains qq. Each of the following qq lines is either 0 l r c or 1 p x.

Output

For each operation of type 0, print the count on its own line. Type 1 produces no output.

Subtasks

  • Subtask 1 (10 points): 1≤n≤601\le n\le 60; 1≤q≤801\le q\le 80; 1≤ai,c≤1091\le a_i,c\le10^9; count queries satisfy 1≤l≤r≤n1\le l\le r\le n; assignments satisfy 1≤p≤min⁡(n,105)1\le p\le\min(n,10^5) and 2≤x≤1092\le x\le10^9.
  • Subtask 2 (20 points): 1≤n≤20001\le n\le 2000; 1≤q≤30001\le q\le 3000; 1≤ai,c≤1091\le a_i,c\le10^9; count queries satisfy 1≤l≤r≤n1\le l\le r\le n; assignments satisfy 1≤p≤min⁡(n,105)1\le p\le\min(n,10^5) and 2≤x≤1092\le x\le10^9.
  • Subtask 3 (30 points): 1≤n≤300001\le n\le 30000; 1≤q≤300001\le q\le 30000; 1≤ai,c≤1091\le a_i,c\le10^9; count queries satisfy 1≤l≤r≤n1\le l\le r\le n; assignments satisfy 1≤p≤min⁡(n,105)1\le p\le\min(n,10^5) and 2≤x≤1092\le x\le10^9.
  • Subtask 4 (40 points): 1≤n≤5000001\le n\le 500000; 1≤q≤1000001\le q\le 100000; 1≤ai,c≤1091\le a_i,c\le10^9; count queries satisfy 1≤l≤r≤n1\le l\le r\le n; assignments satisfy 1≤p≤min⁡(n,105)1\le p\le\min(n,10^5) and 2≤x≤1092\le x\le10^9.

Examples

Input

5
1 2 3 4 5
3
0 1 5 10
1 2 20
0 1 3 10

Output

0
1

Explanation

Initially every value is below 1010, so the first query returns 00. After setting a2=20a_2=20, exactly the second element of the interval [1,3][1,3] is at least 1010, so the final query returns 11.