2182021-02-25 11:24:58kicsiboglarHáromszögekcpp11Runtime error 16/4093ms90728 KiB
#include <iostream>
#include "vector"
#include "algorithm"
using namespace std;

long long n,q,s,maxi,a,b,i;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>q;
    maxi=-99999;
    vector <int> y(n+1,0);
    for (i=1;i<=n;++i)
    {
        cin>>y[i];
        if (maxi<y[i]) maxi=y[i];
    }

    vector <int> x(maxi+1,0);
    for (i=1;i<=n;++i)
    {
        x[y[i]]++;
    }

    for (i=maxi-1;i>=1;--i)
    {
        x[i]+=x[i+1];
    }

    for (i=1;i<=q;++i)
    {
        cin>>a>>b;
        s=abs(b-a)+1;

        if (s<=maxi)
        {
            if (a+b<=maxi)
            {
                cout<<x[s]-x[a+b]<<"\n";
            }
            else cout<<x[s]<<"\n";
        }
        else cout<<"0\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base16/40
1Accepted0/02ms1752 KiB
2Accepted0/01ms1792 KiB
3Accepted0/04ms2700 KiB
4Runtime error0/44ms2384 KiB
5Accepted2/22ms2040 KiB
6Runtime error0/126ms4360 KiB
7Accepted1/193ms90728 KiB
8Accepted2/257ms21528 KiB
9Runtime error0/216ms5528 KiB
10Accepted1/126ms5780 KiB
11Accepted1/126ms5764 KiB
12Accepted2/226ms5760 KiB
13Accepted2/227ms5764 KiB
14Runtime error0/116ms5532 KiB
15Runtime error0/120ms5564 KiB
16Runtime error0/114ms5568 KiB
17Runtime error0/117ms5564 KiB
18Accepted1/128ms7572 KiB
19Accepted2/226ms8192 KiB
20Accepted2/241ms22744 KiB
21Runtime error0/314ms7684 KiB
22Runtime error0/516ms7628 KiB
23Runtime error0/516ms7644 KiB