#include using namespace std; char nl = '\n'; char sp = ' '; using ll = long long; using vb = vector; using vi = vector; using vl = vector; using vvb = vector; using vvi = vector; using vvl = vector; using si = unordered_set; using sl = unordered_set; using tsi = set; using tsl = set; using pii = pair; using pll = pair; using vpii = vector; using vpll = vector; using tmii = map; using tmll = map; using mii = unordered_map; using mll = unordered_map; using pqi = priority_queue; using pqig = priority_queue>; using pql = priority_queue; using pqlg = priority_queue>; using pqpii = priority_queue; using pqpll = priority_queue; #define tp3(T) tuple #define tp4(T) tuple #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sort_and_unique(a) sort(all(a));(a).resize(unique(all(a))-(a).begin()) #define outrange(x,min,max) ((x)<(min) || (x)>(max)) ll _start_time; #define nano (chrono::system_clock::now().time_since_epoch().count()) #define reset_timer _start_time=nano #define chime cout<<((nano-_start_time)/1e9)< ostream& operator<<(ostream& out, const pair& p) { out << '(' << p.first << ',' << p.second << ')'; return out; } template ostream& operator<<(ostream& out, const tuple& tp) { auto &[t1, t2, t3] = tp; out << '(' << t1 << ',' << t2 << ',' << t3 << ')'; return out; } template ostream& operator<<(ostream& out, const vector& v) { for (auto &i : v) out << i << ' '; out << nl; return out; } template ostream& operator<<(ostream& out, const set& v) { for (auto &i : v) out << i << ' '; out << nl; return out; } template ostream& operator<<(ostream& out, const unordered_set& v) { for (auto &i : v) out << i << ' '; out << nl; return out; } template ostream& operator<<(ostream& out, const map& m) { out << '['; for (auto &[k, v] : m) { out << k << ':' << v << sp; } out << "]\n"; return out; } template ostream& operator<<(ostream& out, const unordered_map& m) { out << '['; for (auto &[k, v] : m) { out << k << ':' << v << sp; } out << "]\n"; return out; } namespace segtree_single_point{ #define sti segtree #define stl segtree template auto lambda_add=[](T &x,T &y)->T{ return x+y; }; template auto lambda_min=[](T &x,T &y)->T{ return x auto lambda_max=[](T &x,T &y)->T{ return x>y?x:y; }; template auto lambda_min_max=[](const pair &p1,const pair &p2)->pair{ return {min(p1.first,p2.first),max(p1.second,p2.second)}; }; template class segtree{ public: segtree(const vector &source, function merger, T defaultValue=(T)0){ this->merger=merger; this->defaultValue=defaultValue; int n=source.size(); int L=1; while(L v(2*L,defaultValue); data=v; for(int i=0;i=1;i--) data[i]=merge(data[2*i],data[2*i+1]); } T get(int index){ return data[size+index]; } void add(int index,T value){ put(index,data[size+index]+value); } void put(int index,T value){ _put(size+index,value); } //查询闭区间[l,r] T query(int l,int r){ return _query(1,0,size,l,r+1); } /*查找在l右边的,离l最远的坐标r,使得query(l,r)满足条件。 需要ok函数满足二分查找性质:即当r>l时,ok(query(l,r))-->ok(query(l,r+1))。 找不到则返回-1。 @param l 二分查找的起点。 @param ok 判断某个区间是否合法的函数。 @return 查找到的在l右边的,离l最远的坐标,使得ok(query(l,r))==true。 如果找不到,返回-1。 */ int find_from(int l, const function &ok){ T prev=defaultValue; return _find_from(1,0,size,l,ok,prev); } void show(){ cout< data; function merger; int size; T defaultValue; T merge(T left,T right){ return merger(left,right); } void _put(int i,T value){ data[i]=value; if(i==1) return; int j=i^1; if(i>j) swap(i,j); _put(i>>1,merge(data[i],data[j])); } T _query(int index,int L,int R,int l,int r){ if(L>=r || R<=l) return defaultValue; // int index=(size+L)/(R-L); if(index>=size) { return data[index]; } if(L>=l && R<=r) { return data[index]; } int mid=(L+R)>>1; T ans=defaultValue; if(r>L) ans=merge(ans,_query(2*index,L,mid,l,r)); if(l &ok,T &prev){ if(R<=l) return -1; T after_merge=merge(prev,data[index]); bool this_ok=ok(after_merge); if(index>=size){ if(this_ok){ prev=after_merge; return L; }else return -1; } if(L>=l && this_ok) { prev=after_merge; return R-1; } int mid=(L+R)>>1; if(mid<=l) return _find_from(2*index+1,mid,R,l,ok,prev); int ans=-1; ans=max(ans,_find_from(2*index,L,mid,l,ok,prev)); if(ans==mid-1) { ans=max(ans,_find_from(2*index+1,mid,R,l,ok,prev)); } return ans; } }; } using namespace segtree_single_point; ll mod; const int MAX=100005; ll x[MAX]; ll y[MAX]; ll z[MAX]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,q; cin>>n>>mod>>q; x[0]=y[0]=z[0]=1; for(int i=1;i); while(q--){ int L,M,R; cin>>L>>M>>R; st.add(L,1); if(R