#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 = 1; i <= n; ++i) {
10         scanf("%d%d",&x,&y);
11         b[x] += 1;
12         b[y+1] += -1;
13     }
14     for(int i = 1; i <= 200000; ++i) {
15         b[i] += b[i-1];
16         if(b[i] >= k) {
17             a[i] = 1;
18         }
19         else {
20             a[i] = 0;
21         }
22     }
23     for(int i = 1; i <= 200000; ++i) a[i] += a[i-1];
24     for(int i=1;i<=q;i++) {
25         int x,y;
26         scanf("%d%d",&x,&y);
27         cout<<a[y] - a[x-1]<<endl;
28     }
29     return 0;
30 }
时间: 2024-08-04 16:04:23

#419(div2) B. Karen and Coffee的相关文章

#419(div2) C. Karen and Game

题意:给出一个n*m的矩阵,然后我们可以每一行-1,每一列-1,问是否可以全部变成0 思路:最开始的时候马上就想到了无论怎样,他每一行该减去的时候无论先后都要减去,那么我每一行取一个最小值减去,然后每一列取最小值减去,然后判断是否全部为0,然后学弟给了我一组数据,3 2 2 2 1 1 2 2,题要求最少步骤,那么我们那样就不可以,所以得判断下n和m的大小,n大先做列,那样就减去的数字更多了,m大反之亦然.(手速狗靠这涨了一波大分,o(* ̄▽ ̄*)ブ) 1 #include<bits/stdc+

#419(div2) A. Karen and Morning

题意:给出某个时刻,问多少秒后时刻变成回文的了 思路:A题就直接暴力咯,一秒一秒加,判断,注意:24点为0点 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 string s1; 6 cin>>s1; 7 int x1=s1[0]-'0'; 8 int x2=s1[1]-'0'; 9 int y1=s1[3]-'0'; 10 int y2=s1[4]-'0'; 11 for(int i=0;;i+

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

code force #419(div2)C. Karen and Game

On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or

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

cf386(div2)大一狗ACM之路

#cf386(div2)总结#前两题很顺利的做了出来, c题扔了, D题wrong了5发才A掉.A题签到题, 但是想多了, 代码写的有点长了. 找被整除最小值*7.B题 读题读了一会, 读完了就有思路了, 1A. 字符串问题, 从后往前两个两个的放到新的字符串里, 一个从最左, 一个从最右, 模拟指针扫着放, 最后特判会不会扫到一起.C题跳了没看, 最后做完了D题回来看了一眼没什么思路 日后再说.D题, 恩.. 两个多小时都用在这题上面了, 20分钟的时候做完了B之后就一直再啃D题, 暴力判断啊

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

CF #262 (DIV2) C . Present (二分答案)

output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on