#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; template struct LazySegmentTree{ using F=function; using G=function; using H=function; int sz; vector data; vector lazy; const F f; const G g; const H h; const Monoid e1; const OperatorMonoid e0; LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){ sz=1; while(sz v){ for(int i=0; i=0; i--) data[i]=f(data[2*i+1], data[2*i+2]); } void eval(int k, int l, int r){ if(lazy[k]!=e0){ data[k]=g(data[k], lazy[k], r-l); if(k solve(int n, vector vx, vector vy){ int m=20000; auto f=[](ll x, ll y){ return x+y;}; auto g=[](ll a, ll x, int len){ return x*len;}; auto h=[](ll x, ll y){ return y;}; LazySegmentTree seg(m, f, g, h, 0, 0); vector ans(n); for(int i=0; i=vy[i]){ continue; } if(seg[0]1){ int mid=(l+r)/2; if(seg[mid]>n; ll xa[40040], ya[40040], xb[40040], yb[40040]; for(int i=0; i>xa[i]>>ya[i]>>xb[i]>>yb[i]; } vector vx(n), vy(n); for(int i=0; i