2172021-02-25 11:04:20kicsiboglarHáromszögekcpp11Runtime error 11/40103ms91248 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 (a+b<=maxi)
        {
            cout<<x[s]-x[a+b]<<"\n";
        }
        else cout<<x[s]<<"\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base11/40
1Accepted0/02ms1820 KiB
2Accepted0/01ms1812 KiB
3Accepted0/04ms2728 KiB
4Runtime error0/44ms2376 KiB
5Accepted2/22ms2036 KiB
6Runtime error0/116ms4324 KiB
7Accepted1/1103ms91248 KiB
8Accepted2/243ms23608 KiB
9Runtime error0/214ms8552 KiB
10Accepted1/127ms9936 KiB
11Accepted1/126ms11024 KiB
12Accepted2/226ms12120 KiB
13Accepted2/228ms13292 KiB
14Runtime error0/117ms14204 KiB
15Runtime error0/117ms15216 KiB
16Runtime error0/124ms16224 KiB
17Runtime error0/114ms17236 KiB
18Runtime error0/114ms19724 KiB
19Runtime error0/214ms20592 KiB
20Runtime error0/227ms35232 KiB
21Runtime error0/316ms20896 KiB
22Runtime error0/516ms22016 KiB
23Runtime error0/516ms23184 KiB