This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int b, n, d, m;
void solve1()
{
vector <int> v;
for(int i = 0;i<n;i++)
{
int x;
cin >> x;
v.push_back(x);
}
long long answer = 0;
sort(v.begin(), v.end());
for(int i = 0;i<n-1;i++)
{
if(v[i+1]-v[i]>d) continue;
int l = i + 1, r = n - 1, mid;
while(l+1<r)
{
mid = (l+r)/2;
if(v[mid]-v[i]<=d) l = mid;
else r = mid - 1;
}
if(v[r]-v[i]<=d) answer += r - i;
else answer += l - i;
}
cout << answer << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> b >> n >> d >> m;
if(b==1) solve1();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |