#include <stdio.h>
unsigned X=12345;int rand_(){return(X*=3)>>1;}
int (*compar)(int,int);void sort(int*a,int l,int r){
while(l<r){int i=l,j=l,k=r,t,p=a[l+rand_()%(r-l)];
while(j<k)switch(compar(a[j],p)){case 0:++j;break;case -1:t=a[j],a[j]=a[i],a[i]=t,++i,++j;break;case 1:t=a[--k],a[k]=a[j],a[j]=t;break;}sort(a,l,i);l=k;}
}
int n,q,a[200000][4],z[100000],o1[200000],o2[200000],ff[200002];
void _u(int p,int k){for(;p;p-=p&-p)ff[p]+=k;}
int _q(int p){int z=0;for(;p<=200001;p+=p&-p)z+=ff[p];return z;}
int cmp(int i,int j){return i>j?1:(i<j?-1:0);}
int shinlena(int i,int j){return a[i][0]>a[j][0]?-1:a[i][0]<a[j][0]?1:
(~a[i][3]&&~a[j][3]?0:(~a[i][3]?1:~a[j][3]?-1:0));}
int doppy(int i,int j){return a[i][1]>a[j][1]?-1:a[i][1]<a[j][1]?1:
(~a[i][3]&&~a[j][3]?0:(~a[i][3]?1:~a[j][3]?-1:0));}
void cdq(int l, int r)
{
if(l>=r)return;
int m=(l+r)/2,p0=l,p1=m+1,p2=l;cdq(l,m);cdq(m+1,r);
while(p0<=m&&p1<=r)
if(!~doppy(o1[p0],o1[p1]))o2[p2++]=p0++;
else o2[p2++]=p1++;
while(p0<=m)o2[p2++]=p0++;
while(p1<=r)o2[p2++]=p1++;
for(int jjj,jj,I,j=l;j<=r;++j){jjj=o1[jj=o2[j]];
if((~(I=a[jjj][3]))&&jj>m)z[I]+=_q(a[jjj][2]);
else if(!~I&&jj<=m)_u(a[jjj][2],1);
}
for(int jjj,jj,j=l;j<=r;++j){jjj=o1[jj=o2[j]];
if(!~a[jjj][3]&&jj<=m)_u(a[jjj][2],-1); }
for(int j=l;j<=r;++j)o2[j]=o1[o2[j]];
for(int j=l;j<=r;++j)o1[j]=o2[j];
}
int c[200001],C=1;
int main()
{
scanf("%d%d",&n,&q);
for(int i=0;i<n;++i)scanf("%d%d",a[i],a[i]+1),a[i][2]=a[i][0]+a[i][1],a[i][3]=-1,o1[i]=o2[i]=i,c[C++]=a[i][2];
for(int j=n,i=0;i<q;++j,++i)scanf("%d%d%d",a[j],a[j]+1,a[j]+2),a[j][3]=i,o1[j]=o2[j]=j,c[C++]=a[j][2];
compar=cmp;sort(c,1,C);
for(int z=-2,l,r,i=0;i<n+q;++i){l=1,r=C-1;
while(l<=r){int yy=(l+r)/2;if(c[yy]<a[i][2])l=yy+1;else r=yy-1,z=yy;}a[i][2]=z;
}
compar=shinlena;sort(o1,0,n+q);
cdq(0,n+q-1);
for(int i=0;i<q;++i)printf("%d\n",z[i]);
}
Compilation message
examination.c: In function 'sort':
examination.c:6:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
6 | while(j<k)switch(compar(a[j],p)){case 0:++j;break;case -1:t=a[j],a[j]=a[i],a[i]=t,++i,++j;break;case 1:t=a[--k],a[k]=a[j],a[j]=t;break;}sort(a,l,i);l=k;}
| ^~~~~
examination.c:6:145: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
6 | while(j<k)switch(compar(a[j],p)){case 0:++j;break;case -1:t=a[j],a[j]=a[i],a[i]=t,++i,++j;break;case 1:t=a[--k],a[k]=a[j],a[j]=t;break;}sort(a,l,i);l=k;}
| ^~~~
examination.c: In function 'main':
examination.c:41:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d%d",&n,&q);
| ^~~~~~~~~~~~~~~~~~~
examination.c:42:25: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | for(int i=0;i<n;++i)scanf("%d%d",a[i],a[i]+1),a[i][2]=a[i][0]+a[i][1],a[i][3]=-1,o1[i]=o2[i]=i,c[C++]=a[i][2];
| ^~~~~~~~~~~~~~~~~~~~~~~~~
examination.c:43:33: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | for(int j=n,i=0;i<q;++j,++i)scanf("%d%d%d",a[j],a[j]+1,a[j]+2),a[j][3]=i,o1[j]=o2[j]=j,c[C++]=a[j][2];
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
7 ms |
4444 KB |
Output is correct |
8 |
Correct |
7 ms |
4544 KB |
Output is correct |
9 |
Correct |
7 ms |
4444 KB |
Output is correct |
10 |
Correct |
6 ms |
4544 KB |
Output is correct |
11 |
Correct |
6 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
7 ms |
4568 KB |
Output is correct |
14 |
Correct |
6 ms |
4440 KB |
Output is correct |
15 |
Correct |
6 ms |
4548 KB |
Output is correct |
16 |
Correct |
5 ms |
4440 KB |
Output is correct |
17 |
Correct |
6 ms |
4440 KB |
Output is correct |
18 |
Correct |
3 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
7196 KB |
Output is correct |
2 |
Correct |
252 ms |
7248 KB |
Output is correct |
3 |
Correct |
286 ms |
7200 KB |
Output is correct |
4 |
Correct |
204 ms |
7200 KB |
Output is correct |
5 |
Correct |
187 ms |
7200 KB |
Output is correct |
6 |
Correct |
124 ms |
7248 KB |
Output is correct |
7 |
Correct |
224 ms |
7196 KB |
Output is correct |
8 |
Correct |
215 ms |
7252 KB |
Output is correct |
9 |
Correct |
208 ms |
7212 KB |
Output is correct |
10 |
Correct |
167 ms |
6996 KB |
Output is correct |
11 |
Correct |
176 ms |
6936 KB |
Output is correct |
12 |
Correct |
81 ms |
6684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
7196 KB |
Output is correct |
2 |
Correct |
252 ms |
7248 KB |
Output is correct |
3 |
Correct |
286 ms |
7200 KB |
Output is correct |
4 |
Correct |
204 ms |
7200 KB |
Output is correct |
5 |
Correct |
187 ms |
7200 KB |
Output is correct |
6 |
Correct |
124 ms |
7248 KB |
Output is correct |
7 |
Correct |
224 ms |
7196 KB |
Output is correct |
8 |
Correct |
215 ms |
7252 KB |
Output is correct |
9 |
Correct |
208 ms |
7212 KB |
Output is correct |
10 |
Correct |
167 ms |
6996 KB |
Output is correct |
11 |
Correct |
176 ms |
6936 KB |
Output is correct |
12 |
Correct |
81 ms |
6684 KB |
Output is correct |
13 |
Correct |
284 ms |
7448 KB |
Output is correct |
14 |
Correct |
277 ms |
7508 KB |
Output is correct |
15 |
Correct |
252 ms |
7252 KB |
Output is correct |
16 |
Correct |
226 ms |
7464 KB |
Output is correct |
17 |
Correct |
212 ms |
7552 KB |
Output is correct |
18 |
Correct |
138 ms |
7432 KB |
Output is correct |
19 |
Correct |
275 ms |
7464 KB |
Output is correct |
20 |
Correct |
274 ms |
7520 KB |
Output is correct |
21 |
Correct |
266 ms |
7568 KB |
Output is correct |
22 |
Correct |
165 ms |
6996 KB |
Output is correct |
23 |
Correct |
175 ms |
6892 KB |
Output is correct |
24 |
Correct |
80 ms |
6680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
7 ms |
4444 KB |
Output is correct |
8 |
Correct |
7 ms |
4544 KB |
Output is correct |
9 |
Correct |
7 ms |
4444 KB |
Output is correct |
10 |
Correct |
6 ms |
4544 KB |
Output is correct |
11 |
Correct |
6 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
7 ms |
4568 KB |
Output is correct |
14 |
Correct |
6 ms |
4440 KB |
Output is correct |
15 |
Correct |
6 ms |
4548 KB |
Output is correct |
16 |
Correct |
5 ms |
4440 KB |
Output is correct |
17 |
Correct |
6 ms |
4440 KB |
Output is correct |
18 |
Correct |
3 ms |
4440 KB |
Output is correct |
19 |
Correct |
255 ms |
7196 KB |
Output is correct |
20 |
Correct |
252 ms |
7248 KB |
Output is correct |
21 |
Correct |
286 ms |
7200 KB |
Output is correct |
22 |
Correct |
204 ms |
7200 KB |
Output is correct |
23 |
Correct |
187 ms |
7200 KB |
Output is correct |
24 |
Correct |
124 ms |
7248 KB |
Output is correct |
25 |
Correct |
224 ms |
7196 KB |
Output is correct |
26 |
Correct |
215 ms |
7252 KB |
Output is correct |
27 |
Correct |
208 ms |
7212 KB |
Output is correct |
28 |
Correct |
167 ms |
6996 KB |
Output is correct |
29 |
Correct |
176 ms |
6936 KB |
Output is correct |
30 |
Correct |
81 ms |
6684 KB |
Output is correct |
31 |
Correct |
284 ms |
7448 KB |
Output is correct |
32 |
Correct |
277 ms |
7508 KB |
Output is correct |
33 |
Correct |
252 ms |
7252 KB |
Output is correct |
34 |
Correct |
226 ms |
7464 KB |
Output is correct |
35 |
Correct |
212 ms |
7552 KB |
Output is correct |
36 |
Correct |
138 ms |
7432 KB |
Output is correct |
37 |
Correct |
275 ms |
7464 KB |
Output is correct |
38 |
Correct |
274 ms |
7520 KB |
Output is correct |
39 |
Correct |
266 ms |
7568 KB |
Output is correct |
40 |
Correct |
165 ms |
6996 KB |
Output is correct |
41 |
Correct |
175 ms |
6892 KB |
Output is correct |
42 |
Correct |
80 ms |
6680 KB |
Output is correct |
43 |
Correct |
289 ms |
7508 KB |
Output is correct |
44 |
Correct |
296 ms |
7404 KB |
Output is correct |
45 |
Correct |
284 ms |
7588 KB |
Output is correct |
46 |
Correct |
235 ms |
7556 KB |
Output is correct |
47 |
Correct |
237 ms |
7708 KB |
Output is correct |
48 |
Correct |
134 ms |
7092 KB |
Output is correct |
49 |
Correct |
291 ms |
7800 KB |
Output is correct |
50 |
Correct |
253 ms |
7452 KB |
Output is correct |
51 |
Correct |
253 ms |
7500 KB |
Output is correct |
52 |
Correct |
212 ms |
7296 KB |
Output is correct |
53 |
Correct |
180 ms |
6996 KB |
Output is correct |