762021-01-10 11:52:32Babják PéterHáromszögekcpp11Accepted 40/40144ms32296 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n,q;
    cin>>n>>q;
    vector<int>sz;
    for(int i=0;i<n;i++)
    {
    	int a;cin>>a;
    	sz.push_back(a);
	}
	sort(sz.begin(),sz.end());
	for(int i=0;i<q;i++)
	{
		int a,b;
		cin>>a>>b;
		int mn=abs(a-b)+1;int mx=a+b-1;
		vector<int>::iterator low,up;
		low=lower_bound(sz.begin(),sz.end(),mn);
		up=upper_bound(low,sz.end(),mx);
		cout<<up-low<<endl;
	}
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1756 KiB
2Accepted0/01ms1784 KiB
3Accepted0/012ms2208 KiB
4Accepted4/43ms1976 KiB
5Accepted2/23ms2020 KiB
6Accepted1/1112ms5024 KiB
7Accepted1/1107ms6784 KiB
8Accepted2/2105ms8512 KiB
9Accepted2/2111ms10300 KiB
10Accepted1/1115ms11440 KiB
11Accepted1/1108ms12500 KiB
12Accepted2/2118ms13592 KiB
13Accepted2/2115ms14772 KiB
14Accepted1/1126ms16684 KiB
15Accepted1/1144ms18352 KiB
16Accepted1/1109ms20000 KiB
17Accepted1/1108ms21848 KiB
18Accepted1/1105ms23408 KiB
19Accepted2/2103ms24960 KiB
20Accepted2/2105ms26624 KiB
21Accepted3/3107ms28404 KiB
22Accepted5/5115ms30372 KiB
23Accepted5/5128ms32296 KiB