#![allow(unused_imports)] #![allow(dead_code)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::ops::*; use std::io::{Write, BufWriter}; static MOD: usize = 998244353; // static MOD: usize = 1000000007; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::>() }}; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } use std::cmp; use std::marker::PhantomData; // http://beet-aizu.hatenablog.com/entry/2017/12/01/225955 pub trait Monoid { type T: Copy + Clone + std::fmt::Debug + PartialOrd; fn id() -> Option { None } // TxT->T fn tt_op(l: &Option, r: &Option) -> Option; // ExE->E fn ee_op(l: &Option, r: &Option) -> Option; // TxE->E fn te_op(l: &Option, r: &Option, len: usize) -> Option; } pub struct Sum {} impl Monoid for Sum { type T = i64; #[inline] // add fn tt_op(l: &Option, r: &Option) -> Option { match (l.clone(), r.clone()) { (Some(l), Some(r)) => Some(l+r), (Some(l), None) => Some(l), (None, Some(r)) => Some(r), (None, None) => None, } } // overwrite fn ee_op(l: &Option, r: &Option) -> Option { match (l.clone(), r.clone()) { (Some(l), Some(r)) => Some(r), (Some(l), None) => None, (None, Some(r)) => Some(r), (None, None) => None, } } // overwrite fn te_op(l: &Option, r: &Option, len: usize) -> Option { match (l.clone(), r.clone()) { (Some(l), Some(r)) => Some(r*len as Self::T), (Some(l), None) => None, (None, Some(r)) => Some(r), (None, None) => None, } } } pub struct SegmentTree { data: Vec>, lazy_data: Vec>, size: usize, size_p2: usize, } impl SegmentTree { pub fn from_vec(v: Vec) -> SegmentTree { let size = v.len(); let mut size_p2 = 1; while size_p2 < v.len() { size_p2 *= 2; } let mut data = vec![None; size_p2 * 2]; for (i, x) in v.into_iter().enumerate() { data[size_p2 + i] = Some(x); } for i in (0..size_p2).rev() { data[i] = M::tt_op(&data[i * 2 + 0], &data[i * 2 + 1]); } let mut lazy_data = vec![None; size_p2 * 2]; SegmentTree { data: data, lazy_data: lazy_data, size: size, size_p2: size_p2, } } pub fn size(&self) -> usize { self.size } pub fn eval(&mut self, l: usize, r: usize, k: usize){ if self.lazy_data[k].is_some() { self.data[k] = M::te_op(&self.data[k], &self.lazy_data[k],r-l); if r-l>1 { self.lazy_data[2*k+0] = M::ee_op(&self.data[2*k+0], &self.lazy_data[k]); self.lazy_data[2*k+1] = M::ee_op(&self.data[2*k+1], &self.lazy_data[k]); } self.lazy_data[k] = None; } } pub fn lazy_update(&mut self, a: usize, b: usize, l: usize, r: usize, k: usize, value: M::T) { self.eval(l,r,k); if b<=l || r<=a {return;} if a<=l && r<=b { self.lazy_data[k] = M::ee_op(&self.lazy_data[k], &Some(value)); self.eval(l,r,k); } else{ self.lazy_update(a,b,l,(l+r)/2,2*k+0,value.clone()); self.lazy_update(a,b,(l+r)/2,r,2*k+1,value.clone()); self.data[k] = M::tt_op(&self.data[2*k+0], &self.data[2*k+1]); } } pub fn update(&mut self, a: usize, b:usize, value: M::T){ self.lazy_update(a,b,0,self.size_p2,1,value); } pub fn lazy_query(&mut self, a: usize, b: usize, l: usize, r: usize, k: usize) -> Option { self.eval(l,r,k); if a<=l && r<=b {return self.data[k].clone();} if b<=l || r<=a {return None;} let res1 = self.lazy_query(a, b, l, (l+r)/2, 2*k+0); let res2 = self.lazy_query(a, b, (l+r)/2, r, 2*k+1); M::tt_op(&res1, &res2) } pub fn query(&mut self, l: usize, r: usize) -> Option { self.lazy_query(l,r,0,self.size_p2,1) } } fn solve() { input! { n: usize, q: usize, xlr: [(usize,usize,usize);q], } type Seg = SegmentTree; let mut seg = Seg::from_vec(vec![0 as i64;n]); let mut score_a = 0; let mut score_b = 0; let base = 1000000000; for &(x,l,r) in &xlr { if x==0 { let val = seg.query(l,r+1).unwrap(); let ap = val/base; let bp = val%base; if ap>bp {score_a += ap;} if ap