#include #include #include #include #include #include using namespace std; // depth = N means that there is 2^N leaf nodes // int may be changed to another type // T = current value, U = value pending propagation template struct segmenttree_lazy{ // lazy param of node x has not been applied to node x and all nodes below it unsigned Depth; unique_ptr[]> arr; segmenttree_lazy(unsigned depth):Depth(depth),arr(make_unique[]>(1<<(depth+1))){} T effective_value(size_t index, size_t, size_t){ return arr[index].first+arr[index].second; // combiner for lazy value with real value } void propagate(size_t index, size_t rb, size_t re){ auto prop_val=arr[index].second; // propagation function... arr[index].first=effective_value(index,rb,re); arr[index].second=0; arr[index<<1].second+=prop_val; arr[(index<<1)+1].second+=prop_val; } void update(size_t index, size_t rb, size_t re, size_t ib, size_t ie, unsigned val){ if(rb==ib&&re==ie){ arr[index].second+=val; // update lazy storage return; } //propagate(index,rb,re); // no need size_t rm=(rb+re)>>1; if(ib>1; if(ib>t; while(t-->0){ unsigned n,m; cin>>m>>n; unique_ptr[]> ecboard = make_unique[]>(m); unique_ptr[]> dmboard = make_unique[]>(m); { unique_ptr tarr = make_unique(n); unique_ptr sarr = make_unique(n); unique_ptr darr = make_unique(n); for(unsigned i=0;i>tarr[i]; for(unsigned i=0;i>sarr[i]; for(unsigned i=0;i>darr[i]; for(unsigned i=0;i best_vals = make_unique(m); { segmenttree_lazy ecdp(16), dmdp(16); //unique_ptr ecdp = make_unique(m); //unique_ptr dmdp = make_unique(m); //multiset> ecmax, ecmin; for(unsigned i=0;i