#include <bits/stdc++.h>
using namespace std;
const int N=100005,M=75;
int b,n,d,m;
//////////////////////////////////
void so1()
{
int a[N];
for(int i=0;i<n;++i)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
long long ans=0;
int j=-1;
for(int i=0;i<n;++i)
{
while(1)
{
if((a[i]-a[j+1])<=d)
break;
++j;
}
ans+=(i-j-1);
}
cout<<ans<<endl;
}
//////////////////////////////////
//////////////////////////////////
struct ban
{
int x,y;
};
bool operator<(const ban& a,const ban& b)
{
if(a.x<b.x)
return true;
if(a.x>b.x)
return false;
return a.y<b.y;
}
map<int,int> t[M*1000*4];
void ubd_f(int pos,int y)
{
while(y<=m+m)
{
t[pos][y]++;
y+=(y&(-y));
}
}
int qry_f(int pos,int y)
{
int ans=0;
while(y>=1)
{
if(t[pos].find(y)!=t[pos].end())
ans+=t[pos][y];
y-=(y&(-y));
}
return ans;
}
void ubd_t(int tl,int tr,int x,int y,int pos)
{
ubd_f(pos,y);
if(tl==tr)
return;
int mid=(tl+tr)/2;
if(x<=mid)
ubd_t(tl,mid,x,y,pos*2);
else
ubd_t(mid+1,tr,x,y,pos*2+1);
}
long long qry_t(int tl,int tr,int l,int r,int y,int pos)
{
if(l>r)
return 0;
if(tl==l && tr==r)
return qry_f(pos,m+m)-qry_f(pos,y-1);
int mid=(tl+tr)/2;
return qry_t(tl,mid,l,min(r,mid),y,pos*2)+qry_t(mid+1,tr,max(l,mid+1),r,y,pos*2+1);
}
void so2()
{
ban a[N];
for(int i=0;i<n;++i)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a,a+n);
long long ans=0;
for(int i=0;i<n;++i)
{
if(a[i].x+a[i].y-d<=m+m)
ans+=qry_t(1,m,1,a[i].y,max(a[i].x+a[i].y-d,1),1);
ubd_t(1,m,a[i].y,a[i].x+a[i].y,1);
}
for(int i=0;i<=m*4;++i)
t[i].clear();
for(int i=0;i<n;++i)
{
if(a[i].x-a[i].y-d+m<=m+m)
ans+=qry_t(1,m,a[i].y+1,m,max(a[i].x-a[i].y-d+m,1),1);
ubd_t(1,m,a[i].y,a[i].x-a[i].y+m,1);
}
cout<<ans<<endl;
}
//////////////////////////////////
//////////////////////////////////
void sot()
{
int a[N][3];
for(int i=0;i<n;++i)
{
for(int j=0;j<b;++j)
scanf("%d",&a[i][j]);
}
long long ans=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<i;++j)
{
int yd=0;
for(int k=0;k<b;++k)
{
yd+=abs(a[i][k]-a[j][k]);
}
if(yd<=d)
++ans;
}
}
cout<<ans<<endl;
}
//////////////////////////////////
int main()
{
scanf("%d%d%d%d",&b,&n,&d,&m);
if(b==1)
so1();
if(b==2)
so2();
if(b==3)
sot();
return 0;
}
Compilation message
pairs.cpp: In function 'int main()':
pairs.cpp:150:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(b==3)
^~
pairs.cpp:152:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
return 0;
^~~~~~
pairs.cpp: In function 'void so1()':
pairs.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
pairs.cpp: In function 'void so2()':
pairs.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a[i].x,&a[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp: In function 'void sot()':
pairs.cpp:123:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i][j]);
~~~~~^~~~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:145:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d",&b,&n,&d,&m);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
16 ms |
14456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
15148 KB |
Output is correct |
2 |
Correct |
34 ms |
15228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
15608 KB |
Output is correct |
2 |
Correct |
41 ms |
15608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
15604 KB |
Output is correct |
2 |
Correct |
41 ms |
15724 KB |
Output is correct |
3 |
Correct |
40 ms |
15608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
95 ms |
41120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
306 ms |
16920 KB |
Output is correct |
2 |
Correct |
252 ms |
16760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3532 ms |
52180 KB |
Output is correct |
2 |
Correct |
3221 ms |
52312 KB |
Output is correct |
3 |
Correct |
2054 ms |
32808 KB |
Output is correct |
4 |
Correct |
2868 ms |
44256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4089 ms |
257524 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
14456 KB |
Output is correct |
2 |
Correct |
19 ms |
14512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4089 ms |
16300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4096 ms |
16376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4078 ms |
16384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |