思路:
有点类似于区间修改点查询的树状数组。
实现:
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 const int MAXN = 200005; 6 int a[MAXN], n, k, q; 7 8 int main() 9 { 10 cin >> n >> k >> q; 11 for (int i = 0; i < n; i++) 12 { 13 int l, r; 14 scanf("%d %d", &l, &r); 15 a[l]++; a[r + 1]--; 16 } 17 for (int i = 1; i < MAXN; i++) a[i] += a[i - 1]; 18 for (int i = 1; i < MAXN; i++) 19 if (a[i] >= k) a[i] = 1; 20 else a[i] = 0; 21 for (int i = 1; i < MAXN; i++) a[i] += a[i - 1]; 22 for (int i = 0; i < q; i++) 23 { 24 int l, r; 25 scanf("%d %d", &l, &r); 26 printf("%d\n", a[r] - a[l - 1]); 27 } 28 return 0; 29 }
时间: 2024-10-05 05:41:40