比赛 |
20190521热身赛 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
迷妹 |
最终得分 |
100 |
用户昵称 |
djj |
运行时间 |
0.824 s |
代码语言 |
C++ |
内存使用 |
14.80 MiB |
提交时间 |
2019-05-21 18:18:33 |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar();}
while (c <='9' && c >='0') { x = x * 10 + c - '0'; c = getchar();}
return x * f;
}
int n, q, a, b;
struct szsz{
int c[100010];
void update(int x, int i) {
for (; i <= n; i += i & -i)
c[i] += x;
}
int ask(int x) {
int ans = 0;
for (; x; x -= x & -x)
ans += c[x];
return ans;
}
} zg, ho, xi;
int main() {
freopen("fans.in", "r", stdin);
freopen("fans.out", "w", stdout);
scanf("%d %d", &n, &q);
for (register int i = 1; i <= n; i ++) {
getchar(); a = getchar();
if (a == '1') zg.update(1, i);
else if (a == '2') ho.update(1, i);
else xi.update(1, i);
}
for (register int i = 1; i <= q; i ++) {
a = read(), b = read();
printf("%d %d %d\n", zg.ask(b) - zg.ask(a - 1), ho.ask(b) - ho.ask(a - 1), xi.ask(b) - xi.ask(a - 1));
}
return 0;
}