BZOJ 4397 Breed Counting
来源:互联网 发布:正方形的风管知乎 编辑:程序博客网 时间:2024/06/07 01:42
多水的一道题啊,枉费了我辛辛苦苦码的莫队。。。
目测线段树啥的都能搞,不过好蠢。。。
#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<algorithm> using namespace std; const int maxn=100005; int n,m;int pre[4][maxn]; int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { int tmp; scanf("%d",&tmp); for(int j=1;j<=3;j++) pre[j][i]=pre[j][i-1]+(tmp==j); } while(m--) { int l,r; scanf("%d%d",&l,&r); printf("%d %d %d\n",pre[1][r]-pre[1][l-1],pre[2][r]-pre[2][l-1],pre[3][r]-pre[3][l-1]); } return 0;}
#include<iostream>#include<cstdlib>#include<cstdio> #include<cstring>#include<cmath>#include<algorithm> using namespace std; const int maxn=100005; int n,m;int s[maxn],res[maxn][4],ans[4]; struct query{ int l,r,block,id; bool operator < (const query tmp) const { if(block==tmp.block) return r<tmp.r; return block<tmp.block; }}q[maxn]; int main(){ scanf("%d%d",&n,&m); int bl=sqrt(n); for(int i=1;i<=n;i++) scanf("%d",s+i); for(int i=1;i<=m;i++) scanf("%d%d",&q[i].l,&q[i].r), q[i].id=i, q[i].block=(q[i].l-1)/bl+1; sort(q+1,q+m+1); int l=1,r=0; for(int i=1;i<=m;i++) { while(q[i].l<l) { l--; ans[s[l]]++; } while(q[i].r>r) { r++; ans[s[r]]++; } while(q[i].l>l) { ans[s[l]]--; l++; } while(q[i].r<r) { ans[s[r]]--; r--; } for(int j=1;j<=3;j++) res[q[i].id][j]=ans[j]; } for(int i=1;i<=m;i++) printf("%d %d %d\n",res[i][1],res[i][2],res[i][3]); return 0;}
阅读全文
0 0
- BZOJ 4397 Breed Counting
- BZOJ 4397: [Usaco2015 dec]Breed Counting|暴力
- bzoj 4397: [Usaco2015 dec]Breed Counting 乱搞
- bzoj 4397: [Usaco2015 dec]Breed Counting 前缀和/线段树
- Breed Counting(水?)
- bzoj4397【Usaco2015 Dec】Breed Counting
- bzoj4397: [Usaco2015 dec]Breed Counting
- bzoj4397[Usaco2015 dec]Breed Counting 前缀和
- [BZOJ4397]Breed Counting-前缀和乱搞
- 【BZOJ4397】[Usaco2015 dec]Breed Counting【前缀和】【或莫队】【或线段树】【或可持久化线段树】
- bzoj 1751 [Usaco2005 qua]Lake Counting
- bzoj 4756: [Usaco2017 Jan]Promotion Counting
- Sicily 12747. Breed Proximity
- BZOJ 1914: [Usaco2010 OPen]Triangle Counting 数三角形
- BZOJ 1833 & POJ 2282 The Counting Problem & huangyueying 贪心详解
- bzoj 4756: [Usaco2017 Jan]Promotion Counting (线段树合并)
- BZOJ 4756 [Usaco2017 Jan]Promotion Counting 线段树合并
- BZOJ 4756 Promotion Counting(线段树合并 || dfs)
- Mac下安装VirtualBox并在VirtualBox中安装CentOS7
- 函数指针指向类的静态成员函数
- 【HDU
- Myeclipse 2017 安装与破解
- HDU 2054 A == B 【String 的骚操作 , string find 的应用】
- BZOJ 4397 Breed Counting
- 指针指向类的静态数据成员
- Maven命令的使用
- QT
- PYTHON基础笔记(3)
- c语言 走迷宫问题
- [BZOJ3924][ZJOI2015]幻想乡战略游戏-动态树分治
- 项目实践——一段时间的项目总结
- webpack配置相关知识详解