eolymp
bolt
Try our new interface for solving problems
Məsələlər

Do use segment tree

Do use segment tree

Given a tree with \textbf{n }(\textbf{1 }≤ \textbf{n }≤ \textbf{200000}) nodes and a list of \textbf{q }(\textbf{1 }≤ \textbf{q }≤ \textbf{100000}) queries, process the queries in order and output a value for each output query. The given tree is connected and each node on the tree has a weight \textbf{w_i} (\textbf{−10000 }≤ \textbf{w_i} ≤ \textbf{10000}). Each query consists of a number \textbf{t_i} (\textbf{t_i = 1}, \textbf{2}), which indicates the type of the query, and three numbers \textbf{a_i}, \textbf{b_i} and \textbf{c_i} (\textbf{1 }≤ \textbf{a_i}, \textbf{b_i} ≤ \textbf{n}, \textbf{−10000 }≤ \textbf{c_i} ≤ \textbf{10000}). Depending on the query type, process one of the followings: \begin{itemize} \item (\textbf{t_i = 1}: modification query) Change the weights of all nodes on the shortest path between \textbf{a_i} and \textbf{b_i} (both inclusive) to \textbf{c_i}. \item (\textbf{t_i = 2}: output query) First, create a list of weights on the shortest path between \textbf{a_i} and \textbf{b_i} (both inclusive) in order. After that, output the maximum sum of a non-empty continuous subsequence of the weights on the list.\textbf{c_i} is ignored for output queries. \end{itemize} \InputFile The first line contains two integers \textbf{n} and \textbf{q}. On the second line, there are \textbf{n} integers which indicate \textbf{w_1}, \textbf{w_2}, ..., \textbf{w_n}. Each of the following \textbf{n−1} lines consists of two integers \textbf{s_i} and \textbf{e_i} (\textbf{1} ≤ \textbf{s_i}, \textbf{e_i} ≤ \textbf{n}), which means that there is an edge between \textbf{s_i} and \textbf{e_i}. Finally the following \textbf{q }lines give the list of queries, each of which contains four integers in the format described above. Queries must be processed one by one from top to bottom. \OutputFile For each output query, output the maximum sum in one line.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3 4
1 2 3
1 2
2 3
2 1 3 0
1 2 2 -4
2 1 3 0
2 2 2 0
Çıxış verilənləri #1
6
3
-4
Mənbə JAG Summer 2012, Japan