1422021-01-30 12:23:18kidesoHáromszögekcpp11Runtime error 10/40119ms54600 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define ll long long
using namespace std;

//ifstream cin("harom.in");
//ofstream cout("harom.out");

vector <ll> megold, x;
vector <pair<ll, ll> > y;
ll N, Q, a, b, i, j;

int main()
{
    cin >> N >> Q;
    for (i = 1; i <= N; ++i)
    {
        cin >> a;
        if (x.size() < a + 1) x.resize(a + 1);
        x[a] = 1;
    }

    ll k = x.size() - 1;
    for (i = 1; i <= k; ++i)
        x[i] += x[i - 1];

    y.push_back({ 0,0 });
    for (i = 1; i <= Q; ++i)
    {
        cin >> a >> b;
        y.push_back({ abs(b - a),min(a + b - 1, k) });
    }

    megold.resize(Q + 1, 0);

    for (i = 1; i <= Q; ++i)
    {
        megold[i] = x[y[i].second] - x[y[i].first];
    }


    for (i = 1; i <= Q; ++i)
        cout << megold[i] << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base10/40
1Accepted0/01ms1800 KiB
2Accepted0/01ms1824 KiB
3Accepted0/09ms4300 KiB
4Runtime error0/43ms2220 KiB
5Accepted2/22ms1964 KiB
6Runtime error0/13ms2224 KiB
7Runtime error0/14ms2164 KiB
8Accepted2/2119ms46472 KiB
9Runtime error0/23ms2224 KiB
10Accepted1/170ms6968 KiB
11Accepted1/164ms6916 KiB
12Accepted2/267ms6468 KiB
13Accepted2/268ms6708 KiB
14Runtime error0/13ms2224 KiB
15Runtime error0/13ms2228 KiB
16Runtime error0/14ms2224 KiB
17Runtime error0/13ms2228 KiB
18Runtime error0/179ms9464 KiB
19Runtime error0/286ms9452 KiB
20Runtime error0/2119ms54600 KiB
21Runtime error0/33ms2224 KiB
22Runtime error0/53ms2224 KiB
23Runtime error0/53ms2224 KiB