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 }
时间: 2024-12-08 00:47:14

CF816B Karen and Coffee的相关文章

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

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 u

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(&quo

CodeForces 816B Karen and Coffee(前缀和,大量查询)

CodeForces 816B Karen and Coffee(前缀和,大量查询) Description 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 ac

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

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 u

#419(div2) B. Karen and Coffee

题意:给出n个温度区间,k,Q个询问,每个询问给出一个温度区间x--y.问这之间有多少个温度在给出K的温度区间内. 思路:前缀和小技巧 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N = 3e5+10; 4 5 int n,k,q,x,y,a[N],b[N]; 6 7 int main() { 8 scanf("%d%d%d",&n,&k,&q); 9 for(int i

Codeforces Round #419 (Div. 2) A-E

上紫啦! E题1:59压哨提交成功翻盘 (1:00就做完了调了一个小时,还好意思说出来? (逃)) 题面太长就不复制了,但是配图很可爱所以要贴过来 九条可怜酱好可爱呀 A - Karen and Morning 询问从当前时刻过多久,时间会形成回文串的形式. 暴力呀暴力 1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<

Codeforces Round #419 B

B. Karen and Coffee 题意:输入第一行是n k q 分别表示有n个时间段 q个询问,每次询问给出l r 询问l r 时间内 有几个时间点在给出的时间段中出现不小于k次 思路:n个时间段用扫描线处理,询问就是问 l  r区间内有几个时间点在扫描线中的厚度不小于k,求2次前缀和就可以了 AC代码: #include "iostream" #include "string.h" #include "stack" #include &q

Codeforces Round #419

A Karen and Morning 找最近的回文时间 模拟  往后推 判判就行 //By SiriusRen #include <bits/stdc++.h> using namespace std; int tx,ty,T; bool check(){ int rx=tx/10,ry=tx%10; return ry*10+rx==ty; } int main(){ scanf("%d:%d",&tx,&ty); while(1){ if(check(

Codeforces Round #419 (Div. 2)

1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否则,根据rh和mm的大小来累计sum,然后hh+1,不断尝试. 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int hh,mm; 6 char c; 7 while (cin >> hh >>