#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a; struct SegmentTree{ Int n; vector

v; vector > dat; SegmentTree(){}; SegmentTree(Int n,vector

v):v(v){init(n);build();}; void init(Int n_){ n=1; while(n()); } void build(){ for(auto p:v) dat[p.first+n].emplace_back(p.second); for(Int i=0;i &x){ auto latte=lower_bound(x.begin(),x.end(),d); auto malta=lower_bound(x.begin(),x.end(),c); return Int(latte-malta); }; for(Int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) res+=calc(dat[l++]); if(r&1) res+=calc(dat[--r]); } return res; } }; //INSERT ABOVE HERE signed main(){ Int n,m; cin>>n>>m; vector x(n),a(n),b(n); for(Int i=0;i>x[i]>>a[i]>>b[i]; Int ans=0,res=n+1; vector

vp0,vp1,vp2; for(Int i=0;iInt{ Int res=ans; res+=seg0.query(p,MAX,q,MAX); res+=seg1.v.size()-seg1.query(0,p,0,q); res+=seg2.v.size(); return res; }; auto calc2= [&](Int p,Int q)->Int{ Int res=ans; res+=seg1.query(p,MAX,q,MAX); res+=seg2.v.size()-seg2.query(0,p,0,q); return res; }; Int l=MAX; for(Int p=0;p