문제 링크: https://www.acmicpc.net/problem/14170
14170번: Counting Haybales
Farmer John has just arranged his N haybales (1≤N≤100,000) at various points along the one-dimensional road running across his farm. To make sure they are spaced out appropriately, please help him answer Q queries (1≤Q≤100,000), each asking for the number
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <bits/stdc++.h>
using namespace std;
int n, q, a[100001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
for(int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
while(q--) {
int s, e;
cin >> s >> e;
cout << upper_bound(a, a + n, e) - lower_bound(a, a + n, s) << '\n';
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Silver' 카테고리의 다른 글
백준 14172 Moocast (USACO December 2016 Silver 3번) (0) | 2020.04.03 |
---|---|
백준 14171 Cities and States (USACO December 2016 Silver 2번) (0) | 2020.04.02 |
백준 12003 Diamond Collector (USACO US Open 2016 Silver 2번) (0) | 2020.03.29 |
백준 11996 Circular Barn (USACO February 2016 Silver 1번) (0) | 2020.03.25 |
백준 11975 Build Gates (USACO January 2016 Silver 3번) (0) | 2020.03.12 |