문제 링크: https://www.acmicpc.net/problem/11969
11969번: Breed Counting
Farmer John's \(N\) cows, conveniently numbered \(1 \ldots 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
www.acmicpc.net
Prefix Sum
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 <bits/stdc++.h>
using namespace std;
int N, Q, cow[4][100001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> Q;
for(int i = 1; i <= N; i++) {
int num;
cin >> num;
for(int j = 1; j <= 3; j++) {
if(num == j) cow[j][i] = cow[j][i - 1] + 1;
else cow[j][i] = cow[j][i - 1];
}
}
while(Q--) {
int a, b;
cin >> a >> b;
for(int i = 1; i <= 3; i++)
cout << cow[i][b] - cow[i][a - 1] << ' ';
cout << '\n';
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Silver' 카테고리의 다른 글
백준 11996 Circular Barn (USACO February 2016 Silver 1번) (0) | 2020.03.25 |
---|---|
백준 11975 Build Gates (USACO January 2016 Silver 3번) (0) | 2020.03.12 |
백준 11974 Subsequences Summing to Sevens (USACO January 2016 Silver 2번) (0) | 2020.03.09 |
백준 11973 Angry Cows (USACO January 2016 Silver 1번) (0) | 2020.03.06 |
백준 11968 High Card Wins (USACO December 2015 Silver 2번) (0) | 2020.03.05 |