记录编号 |
435682 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
迷妹 |
最终得分 |
100 |
用户昵称 |
Hallmeow |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.065 s |
提交时间 |
2017-08-10 06:38:50 |
内存使用 |
1.47 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#define pos(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
#define N 101000
int lowbit(int x){return x&(-x);}
int n,q;
int c1[N],c2[N],c3[N];
void update1(int x,int num){
while(x<=n){
c1[x]+=num;
x+=lowbit(x);
}
}
void update2(int x,int num){
while(x<=n){
c2[x]+=num;
x+=lowbit(x);
}
}
void update3(int x,int num){
while(x<=n){
c3[x]+=num;
x+=lowbit(x);
}
}
int tot1(int x){
int sum=0;
while(x>0){
sum+=c1[x];
x-=lowbit(x);
}
return sum;
}
int tot2(int x){
int sum=0;
while(x>0){
sum+=c2[x];
x-=lowbit(x);
}
return sum;
}
int tot3(int x){
int sum=0;
while(x>0){
sum+=c3[x];
x-=lowbit(x);
}
return sum;
}
int main(){
freopen("fans.in","r",stdin);
freopen("fans.out","w",stdout);
scanf("%d%d",&n,&q);
pos(i,1,n){
int x;scanf("%d",&x);
if(x==1) update1(i,1);
if(x==2) update2(i,1);
if(x==3) update3(i,1);
}
pos(i,1,q){
int l,r;scanf("%d%d",&l,&r);
printf("%d %d %d\n",tot1(r)-tot1(l-1),tot2(r)-tot2(l-1),tot3(r)-tot3(l-1));
}
return 0;
}