题目来源CodeForces
评测方式RemoteJudge
难度普及/提高?
时间限制2.50s
内存限制500.00MB
?
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows?nn?coffee recipes. The?ii?-th recipe suggests that coffee should be brewed between?l_{i}li??and?r_{i}ri??degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least?kk?recipes recommend it.
Karen has a rather fickle mind, and so she asks?qq?questions. In each question, given that she only wants to prepare coffee with a temperature between?aa?and?bb?, inclusive, can you tell her how many admissible integer temperatures fall within the range?
The first line of input contains three integers,?nn?,?kk?(?1<=k<=n<=2000001<=k<=n<=200000?), and?qq?(?1<=q<=2000001<=q<=200000?), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next?nn?lines describe the recipes. Specifically, the?ii?-th line among these contains two integers?l_{i}li??and?r_{i}ri??(?1<=l_{i}<=r_{i}<=2000001<=li?<=ri?<=200000?), describing that the?ii?-th recipe suggests that the coffee be brewed between?l_{i}li??and?r_{i}ri??degrees, inclusive.
The next?qq?lines describe the questions. Each of these lines contains?aa?and?bb?, (?1<=a<=b<=2000001<=a<=b<=200000?), describing that she wants to know the number of admissible integer temperatures
between?aa?and?bb?degrees, inclusive.
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between?aa?and?bb?degrees, inclusive.
?
Karen 喜欢咖啡。
她有?n?本食谱,第?i?本食谱包含两个数?li?,ri?,表示这本食谱推荐用?[li?,ri?]?之间的温度(包含?li?.ri?)来煮咖啡。
Karen 认为一个温度?a?是可接受的当且仅当有?≥k?本食谱推荐用?a?来煮咖啡。
Karen 有?q?个问题,每个问题用一对正整数?ai?,bi??来表示,表示她问?[ai?,bi?]?之间有多少个温度是可接受的。
In the first test case, Karen knows?33?recipes.
A temperature is admissible if at least?22?recipes recommend it.
She asks?44?questions.
In her first question, she wants to know the number of admissible integer temperatures between?9292?and?9494?degrees, inclusive. There are?33?:?9292?,?9393?and?9494?degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between?9393?and?9797?degrees, inclusive. There are?33?:?9393?,?9494?and?9797?degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between?9595?and?9696?degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between?9090?and?100100?degrees, inclusive. There are?44?:?9292?,?9393?,?9494?and?9797?degrees are all admissible.
In the second test case, Karen knows?22?recipes.
A temperature is admissible if at least?11?recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
题解:
看一遍题目,就知道要用差分来做。
上AC代码:
?
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll ans[N],n,m,k,sum,a,b,l,r;
int main(){
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
cin>>a>>b;
ans[a]+=1;
ans[b+1]-=1;
if(b>sum) sum=b;
}
for(int i=1;i<=sum;i++){
ans[i]=ans[i-1]+ans[i];
}
for(int i=1;i<N;i++){
if(ans[i]>=m) ans[i]=ans[i-1]+1;
else ans[i]=ans[i-1];
}
for(int i=1;i<=k;i++){
cin>>l>>r;
cout<<ans[r]-ans[l-1]<<endl;
}
return 0;
}