import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.lang.AssertionError import java.util.* import kotlin.math.* val MOD = 1_000_000_007 class RangeUpdateTree(n: Int) { private val zero = 0L private inline fun f(x1: Long, x2: Long) = max(x1, x2) private val N = if (Integer.highestOneBit(n) == n) n else Integer.highestOneBit(n) shl 1 private val dat = LongArray(2 * N){zero} // private inline fun f(a: Int, b: Int) = a + b /** * [l, r) */ fun add(l: Int, r: Int, a: Long) { var left = l + N var right = r - 1 + N while(left <= right) { if ((left and 1) == 1) dat[left] = f(dat[left], a) if ((right and 1) == 0) dat[right] = f(dat[right], a) left = (left + 1) shr 1 // 右の子供なら右の親に移動 right = (right - 1) shr 1 // 左の子供なら左の親に移動 } } fun query(i: Int): Long { var ix = N + i var res: Long = zero while(ix >= 1) { res = f(res, dat[ix]) ix = ix shr 1 } return res } } data class Tri(val x1: Int, val y1: Int, val x2: Int, val y2: Int, val x3: Int, val y3: Int) { fun l() = min(x1, min(x2, x3)) fun r() = max(x1, max(x2, x3)) } interface Query data class Query1(val i: Int, val t: Tri) : Query data class Query2(val i: Int, val l: Int, val r: Int) : Query class Group(val Q: Array) { val maxL = Q.maxBy { it.l }!!.l val R: IntArray init { Q.sortBy { it.r } R = Q.map { it.r }.toIntArray() } val tree = RangeUpdateTree(Q.size) override fun toString(): String { return "[${Q.joinToString(" ")}]" } } fun lb(A: IntArray, x: Int): Int { var l = - 1 var h = A.size while(h - l > 1) { val m = (h + l) / 2 if (A[m] >= x) h = m else l = m } return h } class Solver(stream: InputStream, private val out: java.io.PrintWriter) { private val reader = BufferedReader(InputStreamReader(stream), 32768) fun solve() { val (N, Q) = na(2) fun readTri() = Tri(ni(), ni(), ni(), ni(), ni(), ni()) val T = Array(N) { readTri() } val queries = Array(Q) { if (ni() == 1) Query1(it, readTri()) else Query2(it, ni(), ni()) } debug{"${queries.joinToString(" ")}"} val Q2 = queries.filterIsInstance().toTypedArray() if (Q2.isEmpty()) return Q2.sortBy { it.l } debug{"${Q2.joinToString(" ")}"} val n = sqrt(Q2.size.toDouble()).toInt() // 1グループあたりのquery数の最大 val m = (Q2.size + n - 1)/n // group数 debug{"n:$n m:$m"} val G = Array(m) { val q2 = Q2.slice(n*it until min(Q2.size, n*(it + 1))) Group(q2.toTypedArray()) } debug{"${G.joinToString(" ")}"} val qid2Pos = Array(Q){ Pair(-1, -1) } for (g in G.indices) { for (i in G[g].Q.indices) { qid2Pos[G[g].Q[i].i] = Pair(g, i) } } fun calc(t: Tri): Long = run { abs((t.x1-t.x3).toLong()*(t.y2-t.y3) - (t.x2 - t.x3).toLong()*(t.y1-t.y3)) } fun add(t: Tri) { val v = calc(t) val l = t.l() val r = t.r() debug{"l:$l r:$r"} for (g in G) { if (l >= g.maxL) { val j = lb(g.R, r) g.tree.add(j, g.Q.size, v) } else { for (i in 0 until g.Q.size) { if (g.Q[i].l <= l && r <= g.Q[i].r) { g.tree.add(i, i + 1, v) } } break } } } for (t in T) { add(t) } for (qid in queries.indices) { val q = queries[qid] when(q) { is Query1 -> add(q.t) is Query2 -> { val (g, i) = qid2Pos[qid] val ans = G[g].tree.query(i) if (ans == 0L) out.println(-1) else out.println(ans) } else -> {} } } } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null private fun next(): String { while (tokenizer == null || !tokenizer!!.hasMoreTokens()) { tokenizer = StringTokenizer(reader.readLine()) } return tokenizer!!.nextToken() } private fun ni() = next().toInt() private fun nl() = next().toLong() private fun ns() = next() private fun na(n: Int, offset: Int = 0): IntArray { return IntArray(n) { ni() + offset } } private fun nal(n: Int, offset: Int = 0): LongArray { val res = LongArray(n) for (i in 0 until n) { res[i] = nl() + offset } return res } private fun na2(n: Int, offset: Int = 0): Array { val a = Array(2){IntArray(n)} for (i in 0 until n) { for (e in a) { e[i] = ni() + offset } } return a } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } /** * コーナーケースでエラー出たりするので、debug(dp[1])のように添え字付きの場合はdebug{}をつかうこと */ private inline fun debug(a: LongArray) { debug { a.joinToString(" ") } } private inline fun debug(a: IntArray) { debug { a.joinToString(" ") } } private inline fun debug(a: BooleanArray) { debug { toString(a) } } private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")} private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()} private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())} companion object { // TestRunnerから呼びたいので単純なmainじゃだめ fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() } } } /** * judgeから呼ばれる */ fun main() = Solver.main()