CF816B Karen and Coffee

Posted 王宜鸣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF816B Karen and Coffee相关的知识,希望对你有一定的参考价值。

思路:

有点类似于区间修改点查询的树状数组。

实现:

 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 }

 

以上是关于CF816B Karen and Coffee的主要内容,如果未能解决你的问题,请参考以下文章

Karen and Coffee CodeForces - 816B (差分数组+预处理前缀和)

CodeForces - 816B Karen and Coffee (线段树的区间插入+单点查询)

#419(div2) B. Karen and Coffee

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

CF 815 A. Karen and Game(暴力,模拟)

CF815C Karen and Supermarket