CF816B Karen and Coffee
思路:
有点类似于区间修改点查询的树状数组。
实现:
#include <iostream>
#include <cstdio>
using namespace std; const int MAXN = ;
int a[MAXN], n, k, q; int main()
{
cin >> n >> k >> q;
for (int i = ; i < n; i++)
{
int l, r;
scanf("%d %d", &l, &r);
a[l]++; a[r + ]--;
}
for (int i = ; i < MAXN; i++) a[i] += a[i - ];
for (int i = ; i < MAXN; i++)
if (a[i] >= k) a[i] = ;
else a[i] = ;
for (int i = ; i < MAXN; i++) a[i] += a[i - ];
for (int i = ; i < q; i++)
{
int l, r;
scanf("%d %d", &l, &r);
printf("%d\n", a[r] - a[l - ]);
}
return ;
}
CF816B Karen and Coffee的更多相关文章
- B. Karen and Coffee
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...
- CodeForces 816B Karen and Coffee(前缀和,大量查询)
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the ...
- codeforces round #419 B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- Karen and Coffee CodeForces - 816B (差分数组+预处理前缀和)
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- Codeforces816B Karen and Coffee 2017-06-27 15:18 39人阅读 评论(0) 收藏
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- Karen and Coffee CF 816B(前缀和)
Description To stay woke and attentive(专注的) during classes, Karen needs some coffee! Karen, a coffee ...
- CF 816B Karen and Coffee【前缀和/差分】
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
随机推荐
- Orcle定时生成表数据作业
--建表 create table table41( id ) not null, --主键 col1 ), col2 ), col3 ), col4 int, col5 timestamp, col ...
- CentOS 5.5 介绍
转载:http://www.osyunwei.com/archives/3625.html 操作系统:CentOS 5.5主机名称:wwwIP地址:192.168.21.128网关:192.168.2 ...
- PowerDesinger15设置字体大小
使用PowerDesigner时,它默认table的字体大小颜色等很难看: 假设通过 Symbol ---> Format进行设置.仅仅能对选中的最改动,新建的Table无效. 能够通过例如以下 ...
- Android内存泄露之开篇
先来想这三个问题 内存泄露是怎么回事 内存会泄露的原因 避免内存泄露 1.内存泄露怎么回事 一个程序中,已经不须要使用某个对象,可是由于仍然有引用指向它垃圾回收器就无法回收它,当然该对象占用的内存就无 ...
- MySQL-子查询,派生表,通用表达式
MySQL-子查询 MySQL子查询是嵌套在另一个查询中的查询. MySQL子查询还可以嵌套在另一个子查询中. MySQL子查询称为内部查询,而包含子查询的查询称为外部查询. 查询返回在位于美国(US ...
- JavaScript基础 -- 焦点图轮播(转载)
首先将HTML结构搭建好: <div id="container"> <div id="list" style="left: -60 ...
- ionic2 在执行ionic serve后报 build dev failed: Cannot set property 'fileSystem' of null
ionic2 真是烦人,因为环境依赖的问题还有网络的问题,不知砸的,项目放一段事件不运行就会出问题. 我一开始是 用 cnpm install安装的依赖,其中也报了错, 然后执行 ionic serv ...
- 蓝桥 PREV-30 历届试题 波动数列 【动态规划】
历届试题 波动数列 时间限制:1.0s 内存限制:256.0MB 问题描述 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个数列中后一项总是比前一项增加2或者减少3. ...
- ios23--动画做弹出提示框toast
) { /* [UIView animateWithDuration:2.0 animations:^{ // 执行动画 self.showHUB.text = @"当前购物车已空,赶紧买买 ...
- 安装linux系统-CentOS-6.8-x86_64-minimal.iso
1: 2: 3:单击[Next]继续安装. 4:安装语言,选择[Chinese(Simplified)(中文(简体))]菜单,单击[Next]继续. 5:系统键盘,选择[美国英语式]菜单,单击[下一步 ...