#include #include #define rep(i,n) for(int i=0;i P; typedef pairPP; typedef vector vi; constexpr ll inf=1ll<<61; constexpr ll mod=998244353; typedef modint998244353 mi; int a[200005],b[200005],t[200005],c[200005]; int main(){ int n,m;cin>>n>>m; vectorevent; rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; rep(i,n){ event.push_back(a[i]); event.push_back(b[i]); } rep(i,m){ cin>>t[i]>>c[i]; event.push_back(c[i]); } mapM; sort(all(event)); event.erase(unique(all(event)),event.end()); rep(i,event.size()){ M[event[i]]=i; } vector

V; rep(i,n){ a[i]=M[a[i]]; b[i]=M[b[i]]; V.push_back(P(b[i],a[i])); } vectort0; rep(i,m){ c[i]=M[c[i]]; if(t[i]==0)t0.push_back(c[i]); else { V.push_back(P(c[i],inf)); } } sort(all(V)); fenwick_treefw(event.size()); for(auto e:V){ if(e.second==inf){ if(fw.sum(0,e.first+1)==0)continue; else{ int ss=fw.sum(0,e.first+1); int lb=-1,ub=e.first; while(ub-lb>1){ int mi=(ub+lb)/2; if(fw.sum(0,mi+1)==ss){ ub=mi; } else lb=mi; } fw.add(ub,-1); } } else{ fw.add(e.first,1); } } sort(all(t0)); for(int e:t0){ int ss=fw.sum(0,e+1); if(ss==0)continue; else{ int lb=-1,ub=e; while(ub-lb>1){ int mi=(ub+lb)/2; if(fw.sum(0,mi+1)==ss){ ub=mi; } else lb=mi; } fw.add(ub,-1); } } cout<