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

6 3
2
1
1
3
2
1
1 6
3 3
2 4

Sample Output

3 2 1
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 -- 前缀和的更多相关文章

  1. bzoj4397[Usaco2015 dec]Breed Counting*

    bzoj4397[Usaco2015 dec]Breed Counting 题意: 给定一个长度为N的序列,每个位置上的数只可能是1,2,3中的一种.有Q次询问,每次给定两个数a,b,请分别输出区间[ ...

  2. [Usaco2015 dec]Breed Counting

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4397 用线段树维护区间和即可.时间复杂度\(O((N+Q)logN)\). #includ ...

  3. BZOJ 4390: [Usaco2015 dec]Max Flow

    4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submi ...

  4. 【刷题】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 ...

  5. BZOJ 4393: [Usaco2015 Dec]Fruit Feast

    DP #include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf(&q ...

  6. bzoj4397【Usaco2015 Dec】Breed Counting

    4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 29  Solved: 25 ...

  7. 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)

    [BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...

  8. [Usaco2015 dec]Max Flow 树上差分

    [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 353  Solved: 236[Submit][Sta ...

  9. bzoj4393: [Usaco2015 Dec]Fruit Feast

    题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫 ...

随机推荐

  1. react-native关于ios的启动图标设置

    1.首先我们需要使用xcode打开项目,选择项目中的images.xcassets这个文件夹 2.点击AppIcon可以看到右边出现针对不同设备的图标尺寸 3.在左边空白处右击,选择Import... ...

  2. bzoj 3522 tree-dp 暴力

    首先我们知道,这个题可以N^2的做,我们先确定一个根,然后讨论下情况,合法的三个点只可能有三种情况,第一种是三个点有相同的lca,这种情况我们可以用tree-dp来解决,用dis[i][j]表示i为根 ...

  3. 固定bottom,页面其它可滑动实现方案

    利用flex布局, <html> <body> <div class='container'> <div class='content'></di ...

  4. python碎片记录(三)

    1.不换行输出 for i in range(5):    print(i,end=' ')不换行打印,end表示每打印一个后面跟的字符 2.利用枚举方式打印输出索引与数值 a=[7,8,9]for ...

  5. Coursera在线学习---第六节.构建机器学习系统

    备: High bias(高偏差) 模型会欠拟合    High variance(高方差) 模型会过拟合 正则化参数λ过大造成高偏差,λ过小造成高方差 一.利用训练好的模型做数据预测时,如果效果不好 ...

  6. PHP对象5: define / const /static

    define定义全局常量: define('PATH', '/data/home/www'); const也是定义常量, 一般用于类中, 饰成员属性,不可以修饰方法,如下: class Test{ c ...

  7. PHP对象4: final 不允许重写方法或不允许继承类

    final用在方法中,能继承方法, 不允许重写方法 final用在类声名中, 此类就不能继承 <?php class A{ final function say(){ say 'Ok<br ...

  8. PHP提取url

    <?php $str = parse_url('http://localhost/?id=2&cd=2', PHP_URL_QUERY); ECHO $str; parse_str($s ...

  9. LCD之mipi DSI接口驱动调试流程【转】

    转自:http://blog.csdn.net/liwei16611/article/details/68146912 1.LCD MIPI DSI协议 MIPI-DSI是一种应用于显示技术的串行接口 ...

  10. iTextSharp之pdfRead(两个文件文本内容的比较,指定页数的pdf截取,水印的添加)

    using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using System; us ...