// (-inf, x] * (-inf, y] の和を求める // 加算する点は先読みして突っ込んでおく // ---------- begin rectangle sum ---------- pub struct RectangleSum { point: Vec<(Index, Index)>, row: Vec, col: Vec>, bit: Vec>, zero: Weight, } impl RectangleSum where Index: Ord + Copy, Weight: std::ops::Add + Copy, { pub fn new(zero: Weight) -> Self { RectangleSum { point: vec![], row: vec![], col: vec![], bit: vec![], zero: zero, } } pub fn add_point(&mut self, x: Index, y: Index) { self.point.push((x, y)); } pub fn build(&mut self) { let mut row: Vec<_> = self.point.iter().map(|p| p.0).collect(); row.sort(); row.dedup(); let mut col = vec![vec![]; row.len() + 1]; for &(x, y) in self.point.iter() { let mut k = row.binary_search(&x).unwrap() + 1; while let Some(a) = col.get_mut(k) { a.push(y); k += k & (!k + 1); } } let mut bit = vec![vec![]; row.len() + 1]; for (bit, col) in bit.iter_mut().zip(col.iter_mut()).skip(1) { col.sort(); col.dedup(); bit.resize(col.len() + 1, self.zero); } self.row = row; self.col = col; self.bit = bit; } pub fn add(&mut self, x: Index, y: Index, w: Weight) { let mut x = self.row.binary_search(&x).unwrap() + 1; while let Some(bit) = self.bit.get_mut(x) { let mut y = self.col[x].binary_search(&y).unwrap() + 1; while let Some(v) = bit.get_mut(y) { *v = *v + w; y += y & (!y + 1); } x += x & (!x + 1); } } // (-inf, x] * (-inf * y] の和 pub fn find(&self, x: Index, y: Index) -> Weight { let upper_bound = |x: &[Index], v: &Index| -> usize { use std::cmp::Ordering::Less; x.binary_search_by(|p| p.cmp(v).then(Less)).unwrap_err() }; let mut x = upper_bound(&self.row, &x); let mut ans = self.zero; while x > 0 { let mut y = upper_bound(&self.col[x], &y); let bit = &self.bit[x]; while y > 0 { ans = ans + bit[y]; y -= y & (!y + 1); } x -= x & (!x + 1); } ans } } // ---------- end rectangle sum ---------- // ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { self.it.next().unwrap().parse::().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec { self.it.next().unwrap().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } #[derive(Clone, Copy)] struct Value(i64); impl std::ops::Add for Value { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Value(self.0.max(rhs.0)) } } fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter) { let n: usize = sc.next(); let q: usize = sc.next(); let mut a = vec![(0i64, 0i64, 0i64, 0i64, 0i64, 0i64); n]; let mut ask = vec![(0u8, 0i64, 0i64, 0i64, 0i64, 0i64, 0i64); q]; let mut rect = RectangleSum::new(Value(-1)); for a in a.iter_mut() { a.0 = sc.next(); a.1 = sc.next(); a.2 = sc.next(); a.3 = sc.next(); a.4 = sc.next(); a.5 = sc.next(); let l = a.0.min(a.2).min(a.4); let r = a.0.max(a.2).max(a.4); rect.add_point(-l, r); } for a in ask.iter_mut() { a.0 = sc.next(); if a.0 == 1 { a.1 = sc.next(); a.2 = sc.next(); a.3 = sc.next(); a.4 = sc.next(); a.5 = sc.next(); a.6 = sc.next(); let l = a.1.min(a.3).min(a.5); let r = a.1.max(a.3).max(a.5); rect.add_point(-l, r); } else { a.1 = sc.next(); a.2 = sc.next(); } } rect.build(); for a in a { let p = (a.2 - a.0, a.3 - a.1); let q = (a.4 - a.0, a.5 - a.1); let s = (p.0 * q.1 - p.1 * q.0).abs(); let l = a.0.min(a.2).min(a.4); let r = a.0.max(a.2).max(a.4); rect.add(-l, r, Value(s)); } for a in ask { if a.0 == 1 { let p = (a.3 - a.1, a.4 - a.2); let q = (a.5 - a.1, a.6 - a.2); let s = (p.0 * q.1 - p.1 * q.0).abs(); let l = a.1.min(a.3).min(a.5); let r = a.1.max(a.3).max(a.5); rect.add(-l, r, Value(s)); } else { let ans = rect.find(-a.1, a.2).0; writeln!(out, "{}", ans).ok(); } } }