#include using namespace std; #define NDEBUG #include typedef long long ll; typedef unsigned long long ull; typedef pair ii; typedef pair llll; typedef pair dd; typedef vector vi; typedef vector> vvi; typedef vector vii; typedef vector> vvii; typedef vector vll; typedef vector> vvll; typedef vector vb; typedef vector vs; typedef vector vd; #define pb push_back #define eb emplace_back #define rep(var,n) for(int var=0;var<(n);++var) #define rep1(var,n) for(int var=1;var<=(n);++var) #define repC2(vari,varj,n) for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj) #define repC3(vari,varj,vark,n) for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark) #define ALL(c) (c).begin(),(c).end() #define RALL(c) (c).rbegin(),(c).rend() #define whole(f, x, ...) \ ([&](decltype((x)) whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ })(x) #define tr(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define found(s,e) ((s).find(e)!=(s).end()) #define mset(arr,val) memset(arr,val,sizeof(arr)) #define mid(x,y) ((x)+((y)-(x))/2) #define IN(x,a,b) ((a)<=(x)&&(x)<=(b)) #define IN_(x,a,b) ((a)<=(x)&&(x)<(b)) #define tors(a) sort(ALL(a), greater()) #define nC2(n) ((ll)(n)*((n)-1)/2) #define clamp(v,lo,hi) min(max(v,lo),hi) #define ABS(x) max((x),-(x)) #define PQ(T) priority_queue,greater> #define CLEAR(a) a = decltype(a)() template vector vec(size_t len, T elem) { return vector(len, elem); } template inline void amin(T1 & a, T2 const & b) { if (a>b) a=b; } template inline void amax(T1 & a, T2 const & b) { if (a void erase_one(multiset& ms, T val) { auto iter = ms.find(val); if (iter != ms.end()) ms.erase(iter); } inline ll square(ll x) { return x * x; } inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; } inline ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } template inline T mod(T a, T b) { return ((a % b) + b) % b; } #define is_digit(c) ('0'<=(c)&&(c)<='9') #define is_whitespace(c) ((c)==' '||(c)=='\n'||(c)=='\r'||(c)=='\t'||(c)==EOF) void reader(int& x){ x=0; bool neg=false; for(;;){ int k=getchar(); if(k=='-'){ neg=true; break; } if (is_digit(k)){ x=k-'0'; break;} } for(;;){ int k=getchar(); if (!is_digit(k)) break; x=x*10+k-'0'; } if(neg) x=-x; } void reader(long long& x){ x=0; bool neg=false; for(;;){ int k=getchar(); if(k=='-'){ neg=true; break; } if (is_digit(k)){ x=k-'0'; break; } } for(;;){ int k=getchar(); if (!is_digit(k)) break; x=x*10+k-'0'; } if(neg) x=-x; } void reader(unsigned long long& x){ x=0; for(;;){ int k=getchar(); if (is_digit(k)){ x=(unsigned long long)(k-'0'); break; } } for(;;){ int k=getchar(); if (!is_digit(k)) break; x=x*10+k-'0'; } } int reader(char s[]){ int c,i=0; for(;;){ c=getchar(); if (!is_whitespace(c)) break; } s[i++]=c; for(;;){ c=getchar(); if (is_whitespace(c)) break; s[i++]=c; } s[i]='\0'; return i; } int reader(string& s){ int c; for(;;){ c=getchar(); if (!is_whitespace(c)) break; } s.push_back(c); for(;;){ c=getchar(); if (is_whitespace(c)) break; s.push_back(c); } return s.size(); } void reader(char& c){ for(;;){ c=getchar(); if (!is_whitespace(c)) break; } } void writer(int x, char c=0){ int s=0; bool neg=false; char f[10]; if(x<0) neg=true,x=-x; if(x==0) f[s++]='0'; else while(x) f[s++]='0'+x%10,x/=10; if(neg) putchar('-'); while(s--) putchar(f[s]); if(c) putchar(c); } void writer(long long x, char c=0){ int s=0; bool neg=false; char f[20]; if(x<0) neg=true,x=-x; if(x==0) f[s++]='0'; else while(x) f[s++]='0'+x%10,x/=10; if(neg) putchar('-'); while(s--) putchar(f[s]); if(c) putchar(c); } void writer(unsigned long long x, char c=0){ int s=0; char f[20]; if(x==0) f[s++]='0'; else while(x) f[s++]='0'+x%10,x/=10; while(s--) putchar(f[s]); if(c) putchar(c); } void writer(const string& x, char c=0){ for(int i=0;i void reader(T& x, S& y){ reader(x); reader(y); } template void reader(T& x, S& y, U& z){ reader(x); reader(y); reader(z); } template void reader(T& x, S& y, U& z, V& w){ reader(x); reader(y); reader(z); reader(w); } template vector readerArray(int n){ vector ret(n); for(int i=0;i vector> readerMatrix(int n,int m=0){ if (m==0) m = n; vector> ret(n); for(int i=0;i(m); return ret; } template void writerLn(T x){ writer(x,'\n'); } template void writerLn(T x, S y){ writer(x,' '); writer(y,'\n'); } template void writerLn(T x, S y, U z){ writer(x,' '); writer(y,' '); writer(z,'\n'); } template void writerLn(T x, S y, U z, V v){ writer(x,' '); writer(y,' '); writer(z,' '); writer(v,'\n'); } template void writerArrayLn(T x[], int n){ if(n==0){ putchar('\n'); return; } for(int i=0;i void writerArrayLn(vector& x){ writerArrayLn(x.data(),(int)x.size()); } template void writerArrayLnV(T x[], int n){ for(int i=0;i void writerArrayLnV(vector& x){ for(T xi: x) writerLn(xi); } template void writerMatrix(vector>& x){ int n = x.size(); if (n == 0) return; int m = x[0].size(); for (int i=0; i& a,vector& b,bool decrement=true){ a.resize(M); b.resize(M); for(int i=0;i void readerEdges(size_t M,vector& a,vector& b,vector& c,bool decrement=true){ a.resize(M); b.resize(M); c.resize(M); for(int i=0;i void readerEdges(size_t M,vector& a,vector& b,vector& c,vector& d,bool decrement=true){ a.resize(M); b.resize(M); c.resize(M); d.resize(M); for(int i=0;i> make_nxt(int N, int M, vector& a, vector& b){ vector> nxt(N); for(int i=0;i vector>> make_nxt(int N, int M, vector& a, vector& b, vector& c){ vector>> nxt(N); for(int i=0;i struct SegmentTree { int N; vector buf_; using MERGER = function; MERGER merge; T ident; int ceil2(int size) { int n = 1; while (n < size) n *= 2; return n; } SegmentTree(MERGER merge, T ident) : merge(merge), ident(ident) { } SegmentTree(int size, MERGER merge, T ident) : merge(merge), ident(ident) { N = ceil2(size); buf_.assign(N * 2, ident); } SegmentTree(vector ar, MERGER merge, T ident) : merge(merge), ident(ident) { init(ar); } void init(vector& ar) { int size = ar.size(); N = ceil2(size); buf_.assign(N * 2, ident); for (int i = 0; i < size; ++i) update(i, ar[i]); } void update(int i, T x) { i = N + i - 1; buf_[i] = merge(buf_[i], x); while (i > 0) { i = (i - 1) / 2; buf_[i] = merge(buf_[i * 2 + 1], buf_[i * 2 + 2]); } } T query(int lo, int hi) { return query(lo, hi, 0, 0, N); } T query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return ident; if (a <= l && r <= b) { return buf_[k]; } else { T lv = query(a, b, 2 * k + 1, l, (l + r) / 2); T rb = query(a, b, 2 * k + 2, (l + r) / 2, r); return merge(lv, rb); } } void dump() { } }; template struct MaxSegmentTree : SegmentTree { MaxSegmentTree() : SegmentTree([](T a, T b) { return max(a, b); }, numeric_limits::min()) {} MaxSegmentTree(int size) : SegmentTree(size, [](T a, T b) { return max(a, b); }, numeric_limits::min()) {} MaxSegmentTree(vector ar) : SegmentTree(ar, [](T a, T b) { return max(a, b); }, numeric_limits::min()) {} }; template struct SegmentTreeFractionalCascading { vvii seg; vector> rmqs; vvi LL, RR; int sz; SegmentTreeFractionalCascading(vector>& ys, vector& values) { sz = 1; while (sz < ys.size()) sz <<= 1; seg.resize(2 * sz - 1); LL.resize(2 * sz - 1); RR.resize(2 * sz - 1); rmqs.resize(2 * sz - 1); rep(k, ys.size()) { seg[k + (sz - 1)] = ys[k]; vector vals(seg[k + (sz - 1)].size()); rep(i, seg[k + (sz - 1)].size()) vals[i] = values[seg[k + (sz - 1)][i].second]; rmqs[k + (sz - 1)].init(vals); } for (int k = sz - 2; k >= 0; --k) { seg[k].resize(seg[2 * k + 1].size() + seg[2 * k + 2].size()); LL[k].resize(seg[k].size() + 1); RR[k].resize(seg[k].size() + 1); std::merge(ALL(seg[2 * k + 1]), ALL(seg[2 * k + 2]), begin(seg[k])); vector vals(seg[k].size()); rep(i, seg[k].size()) { vals[i] = values[seg[k][i].second]; } rmqs[k].init(vals); int tail1 = 0, tail2 = 0; rep(i, seg[k].size()) { while (tail1 < seg[2 * k + 1].size() && seg[2 * k + 1][tail1] < seg[k][i]) ++tail1; while (tail2 < seg[2 * k + 2].size() && seg[2 * k + 2][tail2] < seg[k][i]) ++tail2; LL[k][i] = tail1, RR[k][i] = tail2; } LL[k][seg[k].size()] = (int)seg[2 * k + 1].size(); RR[k][seg[k].size()] = (int)seg[2 * k + 2].size(); } } void update(int x, int y, int ylo_ix, int yhi_ix, int k, int xlo_ix, int xhi_ix, T newval) { if (ylo_ix >= yhi_ix) return; if (k >= seg.size()) return; if (!IN_(x, xlo_ix, xhi_ix)) return; if (ylo_ix + 1 == yhi_ix) { rmqs[k].update(ylo_ix, newval); } int xmi_ix = (xlo_ix + xhi_ix) >> 1; if (IN_(ylo_ix, 0, LL[k].size()) && IN_(yhi_ix, 0, LL[k].size())) { update(x, y, LL[k][ylo_ix], LL[k][yhi_ix], 2 * k + 1, xlo_ix, xmi_ix, newval); } if (IN_(ylo_ix, 0, RR[k].size()) && IN_(yhi_ix, 0, RR[k].size())) { update(x, y, RR[k][ylo_ix], RR[k][yhi_ix], 2 * k + 2, xmi_ix, xhi_ix, newval); } } void update(int x, int y, T newval) { int ylo_ix = lower_bound(ALL(seg[0]), ii(y, -1)) - begin(seg[0]); int yhi_ix = lower_bound(ALL(seg[0]), ii(y + 1, -1)) - begin(seg[0]); update(x, y, ylo_ix, yhi_ix, 0, 0, sz, newval); } inline T merge(T x, T y) { return max(x, y); } inline T query(int xlo, int xhi, int ylo_ix, int yhi_ix, int k, int xlo_ix, int xhi_ix) { if (ylo_ix > yhi_ix || xhi_ix <= xlo || xhi <= xlo_ix) { return LLONG_MIN; } else if (xlo <= xlo_ix && xhi_ix <= xhi) { return rmqs[k].query(ylo_ix, yhi_ix); } else { int xmi_ix = (xlo_ix + xhi_ix) >> 1; return merge(query(xlo, xhi, LL[k][ylo_ix], LL[k][yhi_ix], 2 * k + 1, xlo_ix, xmi_ix), query(xlo, xhi, RR[k][ylo_ix], RR[k][yhi_ix], 2 * k + 2, xmi_ix, xhi_ix)); } } T query(int xlo, int xhi, int ylo, int yhi) { int ylo_ix = lower_bound(ALL(seg[0]), ii(ylo, -1)) - begin(seg[0]); int yhi_ix = lower_bound(ALL(seg[0]), ii(yhi, -1)) - begin(seg[0]); return query(xlo, xhi, ylo_ix, yhi_ix, 0, 0, sz); } }; ll calc_area(vi& triangle) { ll x1 = triangle[2] - triangle[0]; ll y1 = triangle[3] - triangle[1]; ll x2 = triangle[4] - triangle[0]; ll y2 = triangle[5] - triangle[1]; return ABS(x1 * y2 - x2 * y1); } void solve(int N, int Q, vvi& triangles, vvi& queries) { set xs; vll area(N, 0), q_area(Q, 0); rep(i, N) { for (int j = 0; j < 6; j += 2) { xs.insert(triangles[i][j]); } area[i] = calc_area(triangles[i]); } rep(i, Q) { int L = queries[i].size(); if (L == 6) { for (int j = 0; j < 6; j += 2) { xs.insert(queries[i][j]); } q_area[i] = calc_area(queries[i]); } else { xs.insert(queries[i][0]); xs.insert(queries[i][1]); } } xs.insert(INT_MIN); xs.insert(INT_MAX); map zx; int zxid = 0; vi zxR; for (int x : xs) { zx[x] = zxid++; zxR.pb(x); } vector> tmp(zxid); auto prepare_point = [&](int xmin, int xmax) -> void { if (!found(tmp[xmin], xmax)) tmp[xmin][xmax] = LLONG_MIN; }; rep(i, N) { int xmin = INT_MAX, xmax = INT_MIN; for (int j = 0; j < 6; j += 2) { int x = zx[triangles[i][j]]; amin(xmin, x); amax(xmax, x); } amax(tmp[xmin][xmax], area[i]); } rep(i, Q) { int L = queries[i].size(); int xmin = INT_MAX, xmax = INT_MIN; if (L == 6) { for (int j = 0; j < 6; j += 2) { int x = zx[queries[i][j]]; amin(xmin, x); amax(xmax, x); } prepare_point(xmin, xmax); } else { xmin = zx[queries[i][0]]; xmax = zx[queries[i][1]]; prepare_point(xmin, xmax); } } vvii ys(zxid); vll values; int value_id = 0; rep(x, zxid) { for (auto [y, a] : tmp[x]) { ys[x].eb(y, value_id); values.pb(a); ++value_id; } } assert(value_id == values.size()); SegmentTreeFractionalCascading seg(ys, values); rep(i, Q) { int L = queries[i].size(); int xmin = INT_MAX, xmax = INT_MIN; if (L == 6) { for (int j = 0; j < 6; j += 2) { int x = zx[queries[i][j]]; amin(xmin, x); amax(xmax, x); } seg.update(xmin, xmax, q_area[i]); } else { int l = zx[queries[i][0]], r = zx[queries[i][1]]; ll res = seg.query(l, r, l, r+1); if (res < 0) res = -1; printf("%lld\n", res); } } } int main() { int N, Q; reader(N, Q); vvi triangles(N, vi(6)); rep(i, N) { triangles[i] = readerArray(6); } vvi queries(Q); rep(i, Q) { int op; reader(op); if (op == 1) { queries[i] = readerArray(6); } else { queries[i] = readerArray(2); } } solve(N, Q, triangles, queries); return 0; }