bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和
4397: [Usaco2015 dec]Breed Counting
Time Limit: 10 Sec Memory Limit: 128 MB
Description
Farmer John's N cows, conveniently numbered 1…N, are all standing in a row (they seem to do so often that it now takes very little prompting from Farmer John to line them up). Each cow has a breed ID: 1 for Holsteins, 2 for Guernseys, and 3 for Jerseys. Farmer John would like your help counting the number of cows of each breed that lie within certain intervals of the ordering.
给定一个长度为N的序列,每个位置上的数只可能是1,2,3中的一种。
有Q次询问,每次给定两个数a,b,请分别输出区间[a,b]里数字1,2,3的个数。
Input
The first line of input contains NN and QQ (1≤N≤100,000 1≤Q≤100,000).
The next NN lines contain an integer that is either 1, 2, or 3, giving the breed ID of a single cow in the ordering.
The next QQ lines describe a query in the form of two integers a,b (a≤b).
Output
For each of the QQ queries (a,b), print a line containing three numbers: the number of cows numbered a…b that are Holsteins (breed 1), Guernseys (breed 2), and Jerseys (breed 3).
Sample Input
2
1
1
3
2
1
1 6
3 3
2 4
Sample Output
1 0 0
2 0 1
HINT
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char xB[<<],*xS=xB,*xTT=xB;
#define getc() (xS==xTT&&(xTT=(xS=xB)+fread(xB,1,1<<15,stdin),xS==xTT)?0:*xS++)
#define isd(c) (c>='0'&&c<='9')
inline int read(){
char xchh;
int xaa;
while(xchh=getc(),!isd(xchh));(xaa=xchh-'');
while(xchh=getc(),isd(xchh))xaa=xaa*+xchh-'';return xaa;
}
int n,q,x,y,s[N][];
int main()
{
n=read();q=read();
for(int i=;i<=n;i++)
{
x=read();
s[i][]=s[i-][];
s[i][]=s[i-][];
s[i][]=s[i-][];
s[i][x]++;
}
while(q--)
{
x=read();y=read();
printf("%d %d %d\n",s[y][]-s[x-][],s[y][]-s[x-][],s[y][]-s[x-][]);
}
return ;
}
bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和的更多相关文章
- bzoj4397[Usaco2015 dec]Breed Counting*
bzoj4397[Usaco2015 dec]Breed Counting 题意: 给定一个长度为N的序列,每个位置上的数只可能是1,2,3中的一种.有Q次询问,每次给定两个数a,b,请分别输出区间[ ...
- [Usaco2015 dec]Breed Counting
原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4397 用线段树维护区间和即可.时间复杂度\(O((N+Q)logN)\). #includ ...
- BZOJ 4390: [Usaco2015 dec]Max Flow
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 177 Solved: 113[Submi ...
- 【刷题】BZOJ 4391 [Usaco2015 dec]High Card Low Card
Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of ...
- BZOJ 4393: [Usaco2015 Dec]Fruit Feast
DP #include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf(&q ...
- bzoj4397【Usaco2015 Dec】Breed Counting
4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec Memory Limit: 128 MB Submit: 29 Solved: 25 ...
- 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)
[BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...
- [Usaco2015 dec]Max Flow 树上差分
[Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 353 Solved: 236[Submit][Sta ...
- bzoj4393: [Usaco2015 Dec]Fruit Feast
题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫 ...
随机推荐
- java正则: 忽略大小写匹配
import java.util.regex.Matcher; import java.util.regex.Pattern; import com.sun.org.apache.xerces.int ...
- 74.VS2013和opencv3.1.0安装教程
一.先下载文件 1.VS2013 VS2013有很多版本,专业版,旗舰版,中文英文之类的,所对应的密钥也不一样.我选择的是简体中文专业版.下载链接如下. http://www.musnow.com/t ...
- NoSQL-来自维基百科
NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称. 两者存在许多显著的不同点,其中最重要的是NoSQL不使用SQL作为查询语言.其数据存储可以不需 ...
- mysql视图学习总结(转)
一.使用视图的理由是什么?1.安全性.一般是这样做的:创建一个视图,定义好该视图所操作的数据.之后将用户权限与视图绑定.这样的方式是使用到 了一个特性:grant语句可以针对视图进行授予权限.2.查询 ...
- php琐碎
1.类中的常量,可以用类来引用: class MyClass() { const SUCCESS ="success"; const FAIL ="fail"; ...
- 开始学习MaxCompute
https://help.aliyun.com/document_detail/34615.html?spm=a2c4g.11186623.6.688.jVxTMW
- beego orm操作mysql数据库
慢慢弄起来~~ 按官方操作文档试一下. 那个err重复和user编号问题,以后再弄.. package main import ( "fmt" "github.com/a ...
- 某PCBA企业应用易普优APS实现高级计划排程案例
一.项目介绍 1.生产计划现状 某PCBA企业(以下简称A企业)的产品生产是典型的多品种.小批量.多变化的生产模式.其中产品种类有1000多种,主流的200多种,每个月数百个生产订单,分解到工序以后的 ...
- Typo: In word 拼写检查
Settings->Inspections > Spelling > Typo 评写检查,
- 第七章:Mapping插件
Mapping插件 Knockout设计成允许你使用任何JavaScript对象作为view model.必须view model的一些属性是observable的,你可以使用KO绑定他们到你的UI元 ...