整体二分作为一个常考的比较有趣的算法(就是难),可以巧妙的解决一些本来比较复杂的题目(比如静态区间第k大),作为一个oier,掌握整体二分的思想是很有必要的。
题目描述
Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colonisation due to strange meteor showers, which on the other hand make it an exceptionally interesting object of study.
The member states of BIU have already placed space stations close to the planet's orbit. The stations' goal is to take samples of the rocks flying by.
The BIU Commission has partitioned the orbit into mm sectors, numbered from 11 to mm, where the sectors 11 and mm are adjacent. In each sector there is a single space station, belonging to one of the nn member states.
Each state has declared a number of meteor samples it intends to gather before the mission ends. Your task is to determine, for each state, when it can stop taking samples, based on the meter shower predictions for the years to come.
输入格式
The first line of the standard input gives two integers, nn and mm (1le n,mle 300 0001≤n,m≤300 000), separated by a single space, that denote,respectively, the number of BIU member states and the number of sectors the orbit has been partitioned into.
In the second line there are mm integers o_ioi (1le o_ile n1≤oi≤n),separated by single spaces, that denote the states owning stations in successive sectors.
In the third line there are nn integers p_ipi (1le p_ile 10^91≤pi≤109),separated by single spaces, that denote the numbers of meteor samples that the successive states intend to gather.
In the fourth line there is a single integer kk (1le kle 300 0001≤k≤300 000) that denotes the number of meteor showers predictions. The following kk lines specify the (predicted) meteor showers chronologically. The ii-th of these lines holds three integers l_i,r_i,a_ili,ri,ai (separated by single spaces), which denote that a meteor shower is expected in sectors l_i,l_{i+1},...,r_ili,li+1,...,ri(if l_ile r_ili≤ri) or sectors l_i,l_{i+1},...,m,1,...,r_ili,li+1,...,m,1,...,ri (if l_i>r_i