#include<bits/stdc++.h>
using namespace std;
#define N 100005
int fen[N],s[N],t[N],so[N],to[N],x[N],y[N],z[N],ans[N];
pair<int,int> p[N];
vector<pair<int,int>> q;
void update(int x,int k){
while(x<N){
fen[x]+=k;
x+=x&-x;
}
}
int sol(int x){
int ans=0;
while(x){
ans+=fen[x];
x-=x&-x;
}
return ans;
}
int main(){
int n,m,i,k,now;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)scanf("%d %d",&s[i],&t[i]),p[i]={s[i],i},so[i]=s[i],to[i]=t[i];
for(i=1;i<=m;i++)scanf("%d %d %d",&x[i],&y[i],&z[i]);
sort(p+1,p+n+1);
sort(so+1,so+n+1);
sort(to+1,to+n+1);
for(i=1;i<=m;i++)
if(x[i]+y[i]>=z[i])q.push_back({x[i],i});
sort(q.begin(),q.end());
now=n;
for(i=q.size()-1;i>=0;i--){
while(now&&p[now].first>=q[i].first){
update(lower_bound(to+1,to+n+1,t[p[now].second])-to,1);
now--;
}
ans[q[i].second]=sol(n)-sol(lower_bound(to+1,to+n+1,y[q[i].second])-to-1);
}
q.clear();
for(i=1;i<=n;i++)p[i]={s[i]+t[i],i};
sort(p+1,p+n+1);
for(i=1;i<=m;i++)
if(x[i]+y[i]<z[i])q.push_back({z[i],i});
sort(q.begin(),q.end());
for(k=0;k<2;k++){
for(i=0;i<=n;i++)fen[i]=0;
now=n;
for(i=q.size()-1;i>=0;i--){
while(now&&p[now].first>=q[i].first){
if(k)update(lower_bound(so+1,so+n+1,s[p[now].second])-so,1);
else update(lower_bound(to+1,to+n+1,t[p[now].second])-to,1);
now--;
}
if(k)ans[q[i].second]+=n-now;
if(k)ans[q[i].second]-=sol(lower_bound(so+1,so+n+1,x[q[i].second])-so-1);
else ans[q[i].second]-=sol(lower_bound(to+1,to+n+1,y[q[i].second])-to-1);
}
}
for(i=1;i<=m;i++)printf("%d\n",ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
examination.cpp:28:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | for(i=1;i<=n;i++)scanf("%d %d",&s[i],&t[i]),p[i]={s[i],i},so[i]=s[i],to[i]=t[i];
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
examination.cpp:29:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | for(i=1;i<=m;i++)scanf("%d %d %d",&x[i],&y[i],&z[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
4 ms |
576 KB |
Output is correct |
8 |
Correct |
5 ms |
576 KB |
Output is correct |
9 |
Correct |
5 ms |
580 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
11 |
Correct |
6 ms |
544 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
580 KB |
Output is correct |
14 |
Correct |
4 ms |
576 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
4 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
8476 KB |
Output is correct |
2 |
Correct |
125 ms |
8488 KB |
Output is correct |
3 |
Correct |
159 ms |
8540 KB |
Output is correct |
4 |
Correct |
103 ms |
7756 KB |
Output is correct |
5 |
Correct |
112 ms |
7784 KB |
Output is correct |
6 |
Correct |
91 ms |
7060 KB |
Output is correct |
7 |
Correct |
159 ms |
8444 KB |
Output is correct |
8 |
Correct |
123 ms |
8624 KB |
Output is correct |
9 |
Correct |
120 ms |
8372 KB |
Output is correct |
10 |
Correct |
105 ms |
7636 KB |
Output is correct |
11 |
Correct |
96 ms |
7612 KB |
Output is correct |
12 |
Correct |
64 ms |
6704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
8476 KB |
Output is correct |
2 |
Correct |
125 ms |
8488 KB |
Output is correct |
3 |
Correct |
159 ms |
8540 KB |
Output is correct |
4 |
Correct |
103 ms |
7756 KB |
Output is correct |
5 |
Correct |
112 ms |
7784 KB |
Output is correct |
6 |
Correct |
91 ms |
7060 KB |
Output is correct |
7 |
Correct |
159 ms |
8444 KB |
Output is correct |
8 |
Correct |
123 ms |
8624 KB |
Output is correct |
9 |
Correct |
120 ms |
8372 KB |
Output is correct |
10 |
Correct |
105 ms |
7636 KB |
Output is correct |
11 |
Correct |
96 ms |
7612 KB |
Output is correct |
12 |
Correct |
64 ms |
6704 KB |
Output is correct |
13 |
Correct |
172 ms |
8572 KB |
Output is correct |
14 |
Correct |
175 ms |
8800 KB |
Output is correct |
15 |
Correct |
124 ms |
8524 KB |
Output is correct |
16 |
Correct |
129 ms |
7748 KB |
Output is correct |
17 |
Correct |
172 ms |
7752 KB |
Output is correct |
18 |
Correct |
102 ms |
6912 KB |
Output is correct |
19 |
Correct |
177 ms |
8580 KB |
Output is correct |
20 |
Correct |
165 ms |
8668 KB |
Output is correct |
21 |
Correct |
162 ms |
8776 KB |
Output is correct |
22 |
Correct |
111 ms |
7624 KB |
Output is correct |
23 |
Correct |
97 ms |
7616 KB |
Output is correct |
24 |
Correct |
68 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
4 ms |
576 KB |
Output is correct |
8 |
Correct |
5 ms |
576 KB |
Output is correct |
9 |
Correct |
5 ms |
580 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
11 |
Correct |
6 ms |
544 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
580 KB |
Output is correct |
14 |
Correct |
4 ms |
576 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
4 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
572 KB |
Output is correct |
19 |
Correct |
127 ms |
8476 KB |
Output is correct |
20 |
Correct |
125 ms |
8488 KB |
Output is correct |
21 |
Correct |
159 ms |
8540 KB |
Output is correct |
22 |
Correct |
103 ms |
7756 KB |
Output is correct |
23 |
Correct |
112 ms |
7784 KB |
Output is correct |
24 |
Correct |
91 ms |
7060 KB |
Output is correct |
25 |
Correct |
159 ms |
8444 KB |
Output is correct |
26 |
Correct |
123 ms |
8624 KB |
Output is correct |
27 |
Correct |
120 ms |
8372 KB |
Output is correct |
28 |
Correct |
105 ms |
7636 KB |
Output is correct |
29 |
Correct |
96 ms |
7612 KB |
Output is correct |
30 |
Correct |
64 ms |
6704 KB |
Output is correct |
31 |
Correct |
172 ms |
8572 KB |
Output is correct |
32 |
Correct |
175 ms |
8800 KB |
Output is correct |
33 |
Correct |
124 ms |
8524 KB |
Output is correct |
34 |
Correct |
129 ms |
7748 KB |
Output is correct |
35 |
Correct |
172 ms |
7752 KB |
Output is correct |
36 |
Correct |
102 ms |
6912 KB |
Output is correct |
37 |
Correct |
177 ms |
8580 KB |
Output is correct |
38 |
Correct |
165 ms |
8668 KB |
Output is correct |
39 |
Correct |
162 ms |
8776 KB |
Output is correct |
40 |
Correct |
111 ms |
7624 KB |
Output is correct |
41 |
Correct |
97 ms |
7616 KB |
Output is correct |
42 |
Correct |
68 ms |
6648 KB |
Output is correct |
43 |
Correct |
176 ms |
10512 KB |
Output is correct |
44 |
Correct |
183 ms |
10576 KB |
Output is correct |
45 |
Correct |
178 ms |
10904 KB |
Output is correct |
46 |
Correct |
147 ms |
8964 KB |
Output is correct |
47 |
Correct |
135 ms |
8900 KB |
Output is correct |
48 |
Correct |
108 ms |
6732 KB |
Output is correct |
49 |
Correct |
165 ms |
10364 KB |
Output is correct |
50 |
Correct |
178 ms |
10528 KB |
Output is correct |
51 |
Correct |
187 ms |
10620 KB |
Output is correct |
52 |
Correct |
160 ms |
8704 KB |
Output is correct |
53 |
Correct |
98 ms |
8324 KB |
Output is correct |