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;
const int mxN=1e5;
int b, n, d, m;
long long ans;
namespace subtask2 {
static const int MG1=1.5e5;
array<int, 2> a[mxN];
int ft[MG1];
void upd(int i, int x) {
for(++i; i<MG1; i+=i&-i)
ft[i]+=x;
}
int qry(int i) {
int r=0;
for(; i>0; i-=i&-i)
r+=ft[i];
return r;
}
void solve() {
for(int i=0; i<n; ++i) {
cin >> a[i][0];
if(b^1) {
cin >> a[i][1];
tie(a[i][0], a[i][1])=make_pair(a[i][0]+a[i][1], a[i][0]-a[i][1]-1+m);
}
}
sort(a, a+n);
for(int i=0, j=0; i<n; ++i) {
while(a[j][0]<a[i][0]-d)
upd(a[j++][1], -1);
ans+=qry(a[i][1]+d+1)-qry(a[i][1]-d);
upd(a[i][1], 1);
}
}
}
namespace subtask3 {
static const int MG1=223;
array<int, 3> a[mxN];
array<int, 4> b[mxN];
int c[MG1+1][MG1+1][MG1+1];
void solve() {
for(int i=0; i<n; ++i) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
b[i][0]=a[i][0]+a[i][1]+a[i][2]-3;
b[i][1]=a[i][0]+a[i][1]-a[i][2]-2+m;
b[i][2]=a[i][0]-a[i][1]+a[i][2]-2+m;
b[i][3]=a[i][0]-a[i][1]-a[i][2]-1+2*m;
}
for(int i=0; i<MG1; ++i) {
memset(c, 0, sizeof(c));
for(int j=0; j<n; ++j)
if(b[j][3]==i)
++c[b[j][0]+1][b[j][1]+1][b[j][2]+1];
for(int j1=1; j1<=MG1; ++j1) {
for(int j2=1; j2<=MG1; ++j2) {
for(int j3=1; j3<=MG1; ++j3)
c[j1][j2][j3]+=c[j1][j2][j3-1];
for(int j3=1; j3<=MG1; ++j3)
c[j1][j2][j3]+=c[j1][j2-1][j3];
}
for(int j2=1; j2<=MG1; ++j2)
for(int j3=1; j3<=MG1; ++j3)
c[j1][j2][j3]+=c[j1-1][j2][j3];
}
for(int j=0; j<n; ++j) {
if(b[j][3]-d<=i&&i<=b[j][3]+d) {
int l1=max(b[j][0]-d, 0), r1=min(b[j][0]+d+1, MG1), l2=max(b[j][1]-d, 0), r2=min(b[j][1]+d+1, MG1), l3=max(b[j][2]-d, 0), r3=min(b[j][2]+d+1, MG1);
ans+=c[r1][r2][r3]-c[r1][r2][l3]-c[r1][l2][r3]+c[r1][l2][l3]-c[l1][r2][r3]+c[l1][r2][l3]+c[l1][l2][r3]-c[l1][l2][l3];
}
}
}
ans=(ans-n)/2;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> b >> n >> d >> m;
if(b<3)
subtask2::solve();
else
subtask3::solve();
cout << ans;
}
# | 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... |