312021-01-08 19:55:55mraronHáromszögekcpp11Wrong answer 8/4048ms8968 KiB
#include <iostream>
#include <algorithm>

using namespace std;

int N, Q, a, b, l, r, hol;
int t[100000];

int bi(int x, int y){
    if(x==y) return x;
    int fel = (x+y)/2;
    if(t[fel]>=hol) return bi(x,fel);
    return bi(fel+1,y);
}

int keres(int x){
    hol = x;
    if(t[0]>=x) return N;
    if(t[N-1]<x) return 0;
    return N-bi(0,N-1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> N >> Q;


    if(N<1 || N>100000 || Q<1 || Q>100000) cout << 5/0 << endl;
    for(int i=0; i<N; i++){
        cin >> t[i];
        if(t[i]>1000000) return 0;
        if(t[i]<1 || t[i]>1000000000) cout << 5/0 << endl;
    }
    sort(t,t+N);

    for(int i=0; i<Q; i++){
        cin >> a >> b;
        if(a>1000000 || b>1000000) return 0;
        if(a<1 || b<1 || a>1000000000 || b>1000000000) cout << 5/0 << endl;
        l = max(a,b)-min(a,b)+1; r = a+b;
        cout << keres(l)-keres(r) << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base8/40
1Accepted0/02ms1820 KiB
2Accepted0/01ms1856 KiB
3Accepted0/06ms2156 KiB
4Wrong answer0/41ms2084 KiB
5Accepted2/22ms2100 KiB
6Wrong answer0/11ms2116 KiB
7Wrong answer0/11ms2084 KiB
8Wrong answer0/21ms2096 KiB
9Wrong answer0/21ms2112 KiB
10Accepted1/145ms4092 KiB
11Accepted1/143ms5156 KiB
12Accepted2/248ms6248 KiB
13Accepted2/246ms7404 KiB
14Wrong answer0/11ms6592 KiB
15Wrong answer0/11ms6644 KiB
16Wrong answer0/11ms6616 KiB
17Wrong answer0/11ms6636 KiB
18Wrong answer0/119ms8208 KiB
19Wrong answer0/220ms8968 KiB
20Wrong answer0/21ms8180 KiB
21Wrong answer0/31ms8180 KiB
22Wrong answer0/51ms8176 KiB
23Wrong answer0/51ms8176 KiB