19172022-12-10 00:34:08kdbHáromszögekcpp11Accepted 40/40141ms5328 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<ll>vec(n);
    for (size_t i = 0; i < n; i++) cin >> vec[i];
    sort(vec.begin(), vec.end());
    while (q--)
    {
        ll b, c;
        cin >> b >> c;
        auto l = lower_bound(vec.begin(), vec.end(), abs(c - b) + 1);
        auto r = upper_bound(vec.begin(), vec.end(), b + c - 1);
        cout << r - l << endl;
    }
    return 0;
}
/*
5 6
10 3 4 6 7
5 9
5 7
6 9
6 7
2 3
2 5

*/
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/02ms2052 KiB
3Accepted0/010ms2180 KiB
4Accepted4/44ms2248 KiB
5Accepted2/24ms2456 KiB
6Accepted1/196ms3992 KiB
7Accepted1/1141ms3940 KiB
8Accepted2/2103ms4292 KiB
9Accepted2/287ms4428 KiB
10Accepted1/1101ms4376 KiB
11Accepted1/1119ms4432 KiB
12Accepted2/2109ms4752 KiB
13Accepted2/2104ms4752 KiB
14Accepted1/1115ms4632 KiB
15Accepted1/1131ms4912 KiB
16Accepted1/1120ms5120 KiB
17Accepted1/1133ms5048 KiB
18Accepted1/187ms5048 KiB
19Accepted2/286ms5052 KiB
20Accepted2/286ms5328 KiB
21Accepted3/389ms5292 KiB
22Accepted5/5104ms5320 KiB
23Accepted5/5104ms5312 KiB