Under construction

Still being built. Things may change

Integral of Polynomial Functions and Queries

Time limit1sMemory limit1024 MB

Summary
Given values A_0 to A_N, answer 6 times the integral of the smooth piecewise polynomial g over [a, b] while point values are updated.
Level

Medium7 of 10

Topics
Segment tree, Math, Prefix sum
Solved
No attempts yet

Problem

A sequence A0,A1,A2,⋯ ,ANA_0, A_1, A_2, \cdots, A_N of length N+1N + 1 is given. Then NN polynomial functions f1(x),f2(x),f3(x),⋯ ,fN(x)f_1(x), f_2(x), f_3(x), \cdots, f_N(x) and a function g(x)g(x) are determined by the following conditions.

  • For every nonnegative integer nn with n≤Nn \le N, g(n)=Ang(n) = A_n.
  • For every positive integer nn with n≤Nn \le N, if n−1≤x≤nn - 1 \le x \le n, then g(x)=fn(x)g(x) = f_n(x).
  • g(x)g(x) is differentiable on the interval (0,N)(0, N).
  • The sequence of degrees of f1(x),f2(x),f3(x),⋯ ,fN(x)f_1(x), f_2(x), f_3(x), \cdots, f_N(x), read in order, is as lexicographically early as possible.

Write a program that handles the following queries.

  • 1 i v: Change AiA_i to vv.
  • 2 a b: Print 6×∫abg(x)dx6 \times \int_a^b g(x)dx.

Input

The first line contains NN. (1≤N≤200 000)(1 \le N \le 200\,000)

The second line contains N+1N + 1 integers A0,A1,A2,⋯ ,ANA_0, A_1, A_2, \cdots, A_N, separated by spaces. (−100 000≤Ai≤100 000)(-100\,000 \le A_i \le 100\,000)

The third line contains the number of queries MM. (1≤M≤200 000)(1 \le M \le 200\,000)

Each of the next MM lines contains one query. (0≤i≤N;(0 \le i \le N; −100 000≤v≤100 000;-100\,000 \le v \le 100\,000; 0≤a≤b≤N)0 \le a \le b \le N)

Every input is guaranteed to contain at least one query of type 2.

All input numbers are integers.

Output

For each query of type 2, print the result on its own line, in order. The result of every type 2 query is always an integer, and this can be proven.

Examples1

  1. Example 1

    Input
    2
    0 1 8
    3
    2 0 2
    1 0 1
    2 1 2
    
    Expected output
    24
    20