본문 바로가기

Algorithm

(C++) - 백준(BOJ) 11969번 : Breed Counting

반응형

간단한 구간 합 구하기 문제였습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int cow[4][100001];
 
int main() {
    int n, q;
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        int num;
        cin >> num;
        cow[num][i]++;
        cow[1][i] += cow[1][i - 1];
        cow[2][i] += cow[2][i - 1];
        cow[3][i] += cow[3][i - 1];
    }
    while (q--)
    {
        int a;
        int b;
        cin >> a>> b;
        int cnt = 0;
        cout << cow[1][b]-cow[1][a-1<< ' ' << cow[2][b]-cow[2][a-1<< ' ' << cow[3][b]-cow[3][a-1];
        cout << '\n';
    }
}