#include #include #include using namespace std; //1-indexed #include template struct BIT{ int n; vectorbit; BIT(int n_=0):n(n_),bit(n_+1){} T sum(int i) { T ans=0; for(;i>0;i-=i&-i)ans+=bit[i]; return ans; } void add(int i,T a) { if(i==0)return; for(;i<=n;i+=i&-i)bit[i]+=a; } int lower_bound(T k)//k<=sum(ret) { if(k<=0)return 0; int ret=0,i=1; while((i<<1)<=n)i<<=1; for(;i;i>>=1) if(ret+i<=n&&bit[ret+i] >X[4]; main() { cin>>N>>M; for(int i=0;i>x>>a>>b; X[x].push_back(make_pair(100001-a,100001-b)); } int ans=N; BITP(1<<17),Q(1<<17); for(int i=0;i<3;i++)sort(X[i].begin(),X[i].end()); for(pairp:X[1])P.add(p.second,1); for(pairp:X[2])Q.add(p.second,1); int i[3]={}; int cnt3=X[3].size(); for(int SA=0;SA<=100001;SA++) { for(int j=0;j<3;j++) { while(i[j]