#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5;
namespace d1
{
int tab[N+10];
long long solve()
{
int n,d,m;
cin>>n>>d>>m;
for(int i=1;i<=n;i++)
cin>>tab[i];
sort(tab+1,tab+n+1);
long long ans=0;
for(int i=1,j=1;i<=n;i++)
{
while(tab[i]-tab[j]>d)
j++;
ans+=i-j;
}
return ans;
}
};
namespace d2
{
const int P=27e4;
struct Event
{
int x,y;
int val;
bool operator<(const Event &oth)
{
return x<oth.x;
}
};
pair<int,int> tab[N+10];
vector<Event> ev;
int pot;
int tree[2*P+10];
void add(int x,int c)
{
for(x+=pot-1;x>0;x/=2)
tree[x]+=c;
return;
}
long long read(int l,int r)
{
l=max(1,l);r=min(pot,r);
long long ans=0;
for(l+=pot-1,r+=pot-1;l<=r;l/=2,r/=2)
{
if(l%2==1)
ans+=tree[l++];
if(r%2==0)
ans+=tree[r--];
}
return ans;
}
long long solve()
{
int n,d,m;
cin>>n>>d>>m;
for(int i=1;i<=n;i++)
{
cin>>tab[i].fi>>tab[i].se;
ev.push_back({tab[i].fi-tab[i].se,tab[i].fi+tab[i].se,1});
ev.push_back({tab[i].fi-tab[i].se+d+1,tab[i].fi+tab[i].se,-1});
}
sort(ev.begin(),ev.end());
for(pot=1;pot<2*m;pot++);
long long ans=0;
for(int i=-m,j=0;i<=m;i++)
{
size_t it;
for(it=j;it<ev.size() && ev[it].x==i;it++)
{
if(ev[it].val==-1)
add(ev[it].y,ev[it].val);
}
for(it=j;it<ev.size() && ev[it].x==i;it++)
{
if(ev[it].val==1)
{
ans+=read(ev[it].y-d,ev[it].y+d);
add(ev[it].y,ev[it].val);
//cerr<<ev[it].x<<" "<<ev[it].y<<" ["<<ans<<"]\n";
}
}
j=it;
}
return ans;
}
};
namespace d3
{
const int M=75;
int pref[M+10][2*M+10][2*M+10];
int tab[M+10][2*M+10][2*M+10];
vector<tuple<int,int,int>> t;
int read(int a,int b,int c)
{
if(a<0 || b<0 || c<0)
return 0;
return pref[a][b][c];
}
long long read_d(int a,int b,int c,int d)
{
d++;
return read(a,b,c)-read(a,b-d,c)-read(a,b,c-d)+read(a,b-d,c-d);
}
long long solve()
{
int n,m,d;
cin>>n>>d>>m;
for(int i=1;i<=n;i++)
{
int a,b,c;
cin>>a>>b>>c;
tab[a][b+c][b-c+m]++;
t.emplace_back(a,b+c,b-c+m);
}
long long ans=-n;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=2*m;j++)
{
for(int k=1;k<=2*m;k++)
{
pref[i][j][k]=tab[i][j][k]+read(i,j-1,k)+read(i,j,k-1)-read(i,j-1,k-1);
}
}
}
for(auto [a,b,c]:t)
{
for(int i=1;i<=m;i++)
{
if(abs(a-i)>d)
continue;
ans+=read_d(i,b,c,d-abs(a-i));
}
}
return ans;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int board_type;
cin>>board_type;
if(board_type==1)
cout<<d1::solve();
else if(board_type==2)
cout<<d2::solve();
else
cout<<d3::solve();
cout<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
696 KB |
Output is correct |
2 |
Correct |
15 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
716 KB |
Output is correct |
2 |
Correct |
24 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
708 KB |
Output is correct |
2 |
Correct |
24 ms |
716 KB |
Output is correct |
3 |
Correct |
19 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4032 KB |
Output is correct |
2 |
Correct |
34 ms |
4032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
4000 KB |
Output is correct |
2 |
Correct |
52 ms |
4036 KB |
Output is correct |
3 |
Correct |
44 ms |
4032 KB |
Output is correct |
4 |
Correct |
47 ms |
4032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
4656 KB |
Output is correct |
2 |
Correct |
64 ms |
4592 KB |
Output is correct |
3 |
Correct |
51 ms |
4616 KB |
Output is correct |
4 |
Correct |
50 ms |
4572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
10316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
2692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
87 ms |
11864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
210 ms |
16680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |