66932023-12-16 19:46:47111Háromszögekcpp17Accepted 40/4061ms5088 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be3.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N, Q;
	cin >> N >> Q;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	while (Q--) {
		int a, b;
		cin >> a >> b;
		if (a < b) {
			swap(a, b);
		}
		int ans = lower_bound(v.begin(), v.end(), a + b) - upper_bound(v.begin(), v.end(), a - b);
		cout << ans << '\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/03ms2064 KiB
3Accepted0/07ms2444 KiB
4Accepted4/43ms2340 KiB
5Accepted2/23ms2464 KiB
6Accepted1/150ms3932 KiB
7Accepted1/146ms4228 KiB
8Accepted2/246ms4288 KiB
9Accepted2/246ms4352 KiB
10Accepted1/152ms4364 KiB
11Accepted1/150ms4564 KiB
12Accepted2/252ms4776 KiB
13Accepted2/250ms4796 KiB
14Accepted1/159ms4792 KiB
15Accepted1/152ms4892 KiB
16Accepted1/152ms4780 KiB
17Accepted1/148ms4800 KiB
18Accepted1/145ms4816 KiB
19Accepted2/245ms4820 KiB
20Accepted2/246ms4824 KiB
21Accepted3/346ms5088 KiB
22Accepted5/557ms5000 KiB
23Accepted5/561ms5000 KiB