73942024-01-08 13:36:08anonHáromszögekcpp17Accepted 40/4061ms5948 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
int main() {
    FastIO;
    ll i, a, b, b1, b2, N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    for(i = 0; i < N; i++)
        cin >> A[i];
    sort(all(A));
    for(i = 0; i < Q; i++) {
        cin >> a >> b;
        b1 = upper_bound(all(A), a + b - 1) - A.begin();
        b2 = lower_bound(A.begin(), A.begin() + b1, abs(a - b) + 1) - A.begin();
        cout << b1 - b2 << '\n';
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/03ms2020 KiB
3Accepted0/07ms2468 KiB
4Accepted4/43ms2448 KiB
5Accepted2/23ms2552 KiB
6Accepted1/152ms4240 KiB
7Accepted1/146ms4456 KiB
8Accepted2/246ms4772 KiB
9Accepted2/246ms4660 KiB
10Accepted1/152ms4864 KiB
11Accepted1/150ms5080 KiB
12Accepted2/250ms5344 KiB
13Accepted2/250ms5540 KiB
14Accepted1/159ms5460 KiB
15Accepted1/152ms5680 KiB
16Accepted1/152ms5628 KiB
17Accepted1/148ms5640 KiB
18Accepted1/145ms5672 KiB
19Accepted2/245ms5572 KiB
20Accepted2/246ms5572 KiB
21Accepted3/346ms5840 KiB
22Accepted5/557ms5948 KiB
23Accepted5/561ms5844 KiB