342021-01-08 20:03:06mraronHáromszögekcpp11Wrong answer 8/4048ms2732 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/01ms1824 KiB
2Accepted0/01ms1848 KiB
3Accepted0/04ms1952 KiB
4Wrong answer0/41ms1908 KiB
5Accepted2/21ms1924 KiB
6Wrong answer0/11ms1912 KiB
7Wrong answer0/11ms1912 KiB
8Wrong answer0/21ms1912 KiB
9Wrong answer0/21ms1912 KiB
10Accepted1/148ms2720 KiB
11Accepted1/145ms2732 KiB
12Accepted2/245ms2728 KiB
13Accepted2/245ms2724 KiB
14Wrong answer0/11ms1908 KiB
15Wrong answer0/11ms1908 KiB
16Wrong answer0/11ms1912 KiB
17Wrong answer0/11ms1908 KiB
18Wrong answer0/117ms2684 KiB
19Wrong answer0/218ms2684 KiB
20Wrong answer0/21ms1912 KiB
21Wrong answer0/31ms1916 KiB
22Wrong answer0/51ms1912 KiB
23Wrong answer0/51ms1912 KiB