首页 > 代码库 > Codeforces Round #419 (Div. 2)B. Karen and Coffee

Codeforces Round #419 (Div. 2)B. Karen and Coffee

B. Karen and Coffee

 

题意:给定n个区间,当一个数在k个区间以内则这个数可以被选中。有q个询问,问在某个区间能有多少个数可以被选中。

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 const int MAX_N = 2e5+10;
 5 int a[MAX_N], c[MAX_N], n, k, q;
 6 int main(){
 7     int l, r;
 8     scanf("%d%d%d",&n,&k,&q);
 9     for(int i = 0; i < n; i ++){
10         scanf("%d%d",&l,&r);
11         a[l]++;
12         a[r+1]--;
13     }
14     for(int i = 0; i < MAX_N; i ++){
15         a[i] += a[i-1];
16         c[i] += c[i-1] + (a[i] >= k);
17     }
18     while(q--){
19         scanf("%d%d",&l,&r);
20         printf("%d\n",c[r]-c[l-1]);
21     }
22     return 0;
23 }

 

Codeforces Round #419 (Div. 2)B. Karen and Coffee