This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<bits/stdc++.h>
usingnamespacestd;
typedefpair<int,int>PII;
constintN=300010;
inta[N],al;
intb[N],s[N];// 假定有一个无限长的数轴,数轴上每个坐标上的数都是 0
PIIq[N],p[N];
intql,pl;
intn,m;
// 手写二分
intlower_bound(intq[],intl,intr,intx){
while(l<r){
intmid=(l+r)>>1;
if(q[mid]>=x)
r=mid;
else
l=mid+1;
}
returnl;
}
intmain(){
cin>>n>>m;
while(n--){
intx,c;
cin>>x>>c;
p[pl++]={x,c};
a[al++]=x;
}
intl,r;
while(m--){
cin>>l>>r;
q[ql++]={l,r};
a[al++]=l,a[al++]=r;
}
// ① 排序+去重
sort(a,a+al);
// ② 使用STL的去重函数去重,不用手写的去重,原因:只排序一次,去重一次,不像是二分需要重复使用,性能差别不大,但代码就短的多