#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #include using namespace std; template struct cLtraits_identity{ using type = T; } ; template using cLtraits_try_make_signed = typename conditional< is_integral::value, make_signed, cLtraits_identity >::type; template struct cLtraits_common_type{ using tS = typename cLtraits_try_make_signed::type; using tT = typename cLtraits_try_make_signed::type; using type = typename common_type::type; } ; void*wmem; char memarr[96000000]; template inline auto min_L(S a, T b) -> typename cLtraits_common_type::type{ return (typename cLtraits_common_type::type) a <= (typename cLtraits_common_type::type) b ? a : b; } template inline auto max_L(S a, T b) -> typename cLtraits_common_type::type{ return (typename cLtraits_common_type::type) a >= (typename cLtraits_common_type::type) b ? a : b; } template inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } template void sortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){ int i; pair >*arr; walloc1d(&arr, N, &mem); for(i=(0);i<(N);i++){ arr[i].first = a[i]; arr[i].second.first = b[i]; arr[i].second.second = c[i]; } sort(arr, arr+N); for(i=(0);i<(N);i++){ a[i] = arr[i].first; b[i] = arr[i].second.first; c[i] = arr[i].second.second; } } template void sortA_L(int N, T1 a[], T2 b[], T3 c[], T4 d[], void *mem = wmem){ int i; pair, pair >*arr; walloc1d(&arr, N, &mem); for(i=(0);i<(N);i++){ arr[i].first.first = a[i]; arr[i].first.second = b[i]; arr[i].second.first = c[i]; arr[i].second.second = d[i]; } sort(arr, arr+N); for(i=(0);i<(N);i++){ a[i] = arr[i].first.first; b[i] = arr[i].first.second; c[i] = arr[i].second.first; d[i] = arr[i].second.second; } } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template inline S chmax(S &a, T b){ if(a int coordcomp_L(int n, T arr[], int res[] = NULL, void *mem = wmem){ int i; int k = 0; pair*r; walloc1d(&r, n, &mem); for(i=(0);i<(n);i++){ r[i].first = arr[i]; r[i].second = i; } sort(r, r+n); if(res != NULL){ for(i=(0);i<(n);i++){ if(i && r[i].first != r[i-1].first){ k++; } res[r[i].second] = k; } } else{ for(i=(0);i<(n);i++){ if(i && r[i].first != r[i-1].first){ k++; } arr[r[i].second] = k; } } return k+1; } template int coordcomp_L(int n1, T arr1[], int n2, T arr2[], int res1[] = NULL, int res2[] = NULL, void *mem = wmem){ int i; int k = 0; pair*r; walloc1d(&r, n1+n2, &mem); for(i=(0);i<(n1);i++){ r[i].first = arr1[i]; r[i].second = i; } for(i=(0);i<(n2);i++){ r[n1+i].first = arr2[i]; r[n1+i].second = n1+i; } sort(r, r+n1+n2); for(i=(0);i<(n1+n2);i++){ if(i && r[i].first != r[i-1].first){ k++; } if(r[i].second < n1){ if(res1!=NULL){ res1[r[i].second] = k; } else{ arr1[r[i].second] = k; } } else{ if(res2!=NULL){ res2[r[i].second-n1] = k; } else{ arr2[r[i].second-n1] = k; } } } return k+1; } template struct segtree_Point_Maxval{ int N; int logN; T*mx; void malloc(int maxN, int once = 0){ int i; for(i=1;i 1){ a /= 2; mx[a] =max_L(mx[2*a], mx[2*a+1]); } } inline void change(int a, T val){ mx[a+N] = val; build(a+N); } inline void add(int a, T val){ mx[a+N] += val; build(a+N); } inline T getMaxVal(int a, int b){ T res; T tmp; int fga = 0; int fgb = 0; a += N; b += N; while(a < b){ if(a%2){ if(fga){ res =max_L(res, mx[a]); } else{ res = mx[a]; fga = 1; } a++; } if(b%2){ b--; if(fgb){ tmp =max_L(mx[b], tmp); } else{ tmp = mx[b]; fgb = 1; } } a /= 2; b /= 2; } if(fga==1 && fgb==0){ return res; } if(fga==0 && fgb==1){ return tmp; } if(fga==1 && fgb==1){ res =max_L(res, tmp); return res; } return res; } } ; long long crossProd_L(long long x1, long long y1, long long x2, long long y2){ return x1 * y2 - x2 * y1; } int N; int Q; int T[200000]; int A[200000]; int B[200000]; int C[200000]; int D[200000]; int E[200000]; int F[200000]; int L[200000]; int R[200000]; int ind[200000]; int x[200000]; int y[200000]; long long s[200000]; int qx[200000]; int qy[200000]; void solve(int n, int x[], int y[], long long s[], int q, int x1[], int y1[], long long res[], void *mem = wmem){ int i; int xs; int*larr; int*nx; int*ny; int*qx; int*qy; int*nind; int*qind; long long*sarr; segtree_Point_Maxval t; walloc1d(&larr, 2*n+2*q, &mem); walloc1d(&nx, n, &mem); walloc1d(&ny, n, &mem); walloc1d(&qx, q, &mem); walloc1d(&qy, q, &mem); walloc1d(&nind, n, &mem); walloc1d(&qind, q, &mem); for(i=(0);i<(n);i++){ larr[i] = x[i]; } for(i=(0);i<(n);i++){ larr[n+i] = y[i]; } for(i=(0);i<(q);i++){ larr[n+n+i] = x1[i]; } for(i=(0);i<(q);i++){ larr[n+n+q+i] = y1[i]; } xs =coordcomp_L(2*n+2*q,larr,NULL,mem); for(i=(0);i<(n);i++){ nx[i] = larr[i]; } for(i=(0);i<(n);i++){ ny[i] = larr[n+i]; } for(i=(0);i<(q);i++){ qx[i] = larr[n+n+i]; } for(i=(0);i<(q);i++){ qy[i] = larr[n+n+q+i]; } for(i=(0);i<(n);i++){ nind[i] = i; } for(i=(0);i<(q);i++){ qind[i] = i; } sortA_L(n, nx, ny, nind, mem); sortA_L(q, qx, qy, qind, mem); walloc1d(&sarr, xs, &mem); t.walloc(xs, 0, &mem); t.setN(xs); for(i=(0);i<(xs);i++){ t[i] = sarr[i] = -1; } t.build(); for(i=(q)-1;i>=(0);i--){ while(n && nx[n-1] >= qx[i]){ if(sarr[ny[n-1]] < s[nind[n-1]]){ sarr[ny[n-1]] = s[nind[n-1]]; t.change(ny[n-1], sarr[ny[n-1]]); } n--; } res[qind[i]] = t.getMaxVal(0, qy[i]+1); } } long long res[200000]; long long tmp[200000]; int main(){ wmem = memarr; int i; int j; int k; int nst; int ned; int nn; int qst; int qed; rd(N); rd(Q); { int Q5rsz4fz; for(Q5rsz4fz=(0);Q5rsz4fz<(N);Q5rsz4fz++){ rd(A[Q5rsz4fz]); rd(B[Q5rsz4fz]); rd(C[Q5rsz4fz]); rd(D[Q5rsz4fz]); rd(E[Q5rsz4fz]); rd(F[Q5rsz4fz]); } } nn = N; for(i=(0);i<(Q);i++){ rd(T[i]); if(T[i]==1){ rd(A[nn]); rd(B[nn]); rd(C[nn]); rd(D[nn]); rd(E[nn]); rd(F[nn]); ind[i] = nn++; } if(T[i]==2){ rd(L[i]); rd(R[i]); } } for(i=(0);i<(nn);i++){ x[i] =min_L(min_L(A[i], C[i]), E[i]); y[i] =max_L(max_L(A[i], C[i]), E[i]); s[i] = abs(crossProd_L(C[i]-A[i], D[i]-B[i], E[i]-A[i], F[i]-B[i])); } nst = ned = N; qst = qed = 0; for(i=(0);i<(Q);i++){ if(T[i]==1){ ned++; } else{ res[qed] = -1; for(k=(nst);k<(ned);k++){ if(L[i]<=x[k]&&y[k]<=R[i]){ chmax(res[qed], s[k]); } } qx[qed] = L[i]; qy[qed] = R[i]; qed++; } if(nst + 200 < ned){ if(qst < qed){ solve(nst, x, y, s, qed-qst, qx+qst, qy+qst, tmp+qst); while(qst < qed){ chmax(res[qst], tmp[qst]); qst++; } } nst = ned; } } if(qst < qed){ solve(nst, x, y, s, qed-qst, qx+qst, qy+qst, tmp+qst); while(qst < qed){ chmax(res[qst], tmp[qst]); qst++; } } for(i=(0);i<(qed);i++){ wt_L(res[i]); wt_L('\n'); } return 0; } // cLay version 20210717-1 [beta] // --- original code --- // int N, Q, T[2d5], A[], B[], C[], D[], E[], F[], L[], R[], ind[]; // int x[], y[]; ll s[]; // int qx[], qy[]; // // void solve(int n, int x[], int y[], ll s[], int q, int x1[], int y1[], ll res[], void *mem = wmem){ // int i, xs; // int *larr; // int *nx, *ny, *qx, *qy, *nind, *qind; // ll *sarr; // segtree_Point_Maxval t; // walloc1d(&larr, 2*n+2*q, &mem); // walloc1d(&nx, n, &mem); // walloc1d(&ny, n, &mem); // walloc1d(&qx, q, &mem); // walloc1d(&qy, q, &mem); // walloc1d(&nind, n, &mem); // walloc1d(&qind, q, &mem); // // rep(i,n) larr[i] = x[i]; // rep(i,n) larr[n+i] = y[i]; // rep(i,q) larr[n+n+i] = x1[i]; // rep(i,q) larr[n+n+q+i] = y1[i]; // xs = coordcomp(2*n+2*q,larr,NULL,mem); // rep(i,n) nx[i] = larr[i]; // rep(i,n) ny[i] = larr[n+i]; // rep(i,q) qx[i] = larr[n+n+i]; // rep(i,q) qy[i] = larr[n+n+q+i]; // // rep(i,n) nind[i] = i; // rep(i,q) qind[i] = i; // // sortA(n, nx, ny, nind, mem); // sortA(q, qx, qy, qind, mem); // // walloc1d(&sarr, xs, &mem); // // t.walloc(xs, 0, &mem); // t.setN(xs); // rep(i,xs) t[i] = sarr[i] = -1; // t.build(); // // rrep(i,q){ // while(n && nx[n-1] >= qx[i]){ // if(sarr[ny[n-1]] < s[nind[n-1]]){ // sarr[ny[n-1]] = s[nind[n-1]]; // t.change(ny[n-1], sarr[ny[n-1]]); // } // n--; // } // res[qind[i]] = t.getMaxVal(0, qy[i]+1); // } // } // // ll res[], tmp[]; // { // int i, j, k, nst, ned, nn, qst, qed; // rd(N,Q,(A,B,C,D,E,F)(N)); // nn = N; // rep(i,Q){ // rd(T[i]); // if(T[i]==1) rd(A[nn], B[nn], C[nn], D[nn], E[nn], F[nn]), ind[i] = nn++; // if(T[i]==2) rd(L[i], R[i]); // } // rep(i,nn){ // x[i] = min(A[i], C[i], E[i]); // y[i] = max(A[i], C[i], E[i]); // s[i] = abs(crossProd(C[i]-A[i], D[i]-B[i], E[i]-A[i], F[i]-B[i])); // } // nst = ned = N; // qst = qed = 0; // rep(i,Q){ // if(T[i]==1){ // ned++; // } else { // res[qed] = -1; // rep(k,nst,ned) if(L[i]<=x[k]&&y[k]<=R[i]) res[qed] >?= s[k]; // qx[qed] = L[i]; // qy[qed] = R[i]; // qed++; // } // if(nst + 200 < ned){ // if(qst < qed){ // solve(nst, x, y, s, qed-qst, qx+qst, qy+qst, tmp+qst); // while(qst < qed){ // res[qst] >?= tmp[qst]; // qst++; // } // } // nst = ned; // } // } // if(qst < qed){ // solve(nst, x, y, s, qed-qst, qx+qst, qy+qst, tmp+qst); // while(qst < qed){ // res[qst] >?= tmp[qst]; // qst++; // } // } // rep(i,qed) wt(res[i]); // }