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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <pair<char,char>, pair<char,char>> T;
#define f(i,a,b) for(ll i = a; i < b; i++)
#define fa(i,a,b) for(ll i = a; i >= b; i--)
const int N = 150005, M = 75001;
int b, n, d, m, bit[N];
vector <vector <int>> a;
ll ans;
void upd(int u, int val){
for(; u < N; u = (u|(u+1))) bit[u] += val;
}
int get(int u){
int res = 0;
for(; u >= 0; u = (u&(u+1)) - 1) res += bit[u];
return res;
}
int que(int l, int r){ return get(r) - get(l-1); }
int main(){
cin >> b >> n >> d >> m;
a.resize(n);
f(i,0,n) {
a[i].resize(b);
f(j,0,b) cin >> a[i][j];
}
if(b == 1){
sort(a.begin(), a.end());
int l = 0;
f(i,0,n){
while(a[i][0] - a[l][0] > d) l++;
ans += (ll) (i - l);
}
cout << ans << "\n";
return 0;
}
if(b == 2){
f(i,0,n){
int u = a[i][0] + a[i][1], v = a[i][0] - a[i][1] + M;
a[i][0] = u, a[i][1] = v;
}
sort(a.begin(), a.end());
int l = 0;
f(i,0,n){
while(a[i][0] - a[l][0] > d){
upd(a[l][1], -1);
l++;
}
ans += (ll) que(max(0, a[i][1] - d), min(N-1, a[i][1]+d));
upd(a[i][1], 1);
}
cout << ans << "\n";
return 0;
}
cout << ans << "\n";
return 0;
}
# | 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... |