USACO/Silver
백준 14170 Counting Haybales (USACO December 2016 Silver 1번)
ssam..
2020. 3. 29. 04:34
문제 링크: 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
|