题目点这里
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m;
typedef pair<int,int> PII;
vector<PII> add,query;
vector<int> alls;
const int N=300010;
int a[N],s[N];
int find(int x)
{
return lower_bound(alls.begin(),alls.end(),x)-alls.begin()+1;
}
vector<int>::iterator unique(vector<int> &a)
{
int j=0;
for(int i=0;i<alls.size();i++)
{
if(!i||a[i]!=a[i-1])
a[j++]=a[i];
}
return alls.begin()+j;
}
int main()
{
cin>>n>>m;
while(n--)
{
int a,b;
cin>>a>>b;
add.push_back({
a,b});
alls.push_back(a);
}
while(m--)
{
int l,r;
cin>>l>>r;
query.push_back({
l,r});
alls.push_back(l);
alls.push_back(r);
}
sort(alls.begin(),alls.end());
alls.erase(unique(alls),alls.end());
for(auto it: add)
{
int x=find(it.first);
a[x]+=it.second;
}
for(int i=1;i<=alls.size();i++)
s[i]=s[i-1]+a[i];
for(auto it: query)
{
int l=find(it.first);
int r=find(it.second);
printf("%d\n",s[r]-s[l-1]);
}
return 0;
}