#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ii pair<int,int>
#define orta ((bas+son)>>1)
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define inf 1000000000
#define N 300005
using namespace std;
#define fpos bos
struct query {
int w,val,id,sg;
};
struct seg {
int s[N<<2];
void up(int node,int bas,int son,int x) {
if(bas==x && son==x) {
s[node]++;
return ;
}
if(orta>=x) up(node<<1,bas,orta,x);
else up(node<<1|1,orta+1,son,x);
s[node]=s[node<<1]+s[node<<1|1];
}
int get(int node,int bas,int son,int x,int y) {
if(bas>y || son<x || x>y) return 0;
if(bas>=x && son<=y) return s[node];
return get(node<<1,bas,orta,x,y)+get(node<<1|1,orta+1,son,x,y);
}
} s[2];
int n,q;
int a2[2][N],cnt[2],ans[N];
vector<query> qu[N];
ii ar[N];
int fpos(int w,int val) {
int bas=1,son=cnt[w];
while(bas<=son) {
if(a2[w][orta]<val) bas=orta+1;
else son=orta-1;
}
return bas;
}
void cmp() {
map<int,int> mp[2];
for(int i=1;i<=n;i++) {
mp[0][ar[i].nd]=1;
mp[1][ar[i].st+ar[i].nd]=1;
}
for(int i=0;i<2;i++) {
for(auto& x:mp[i]) {
a2[i][++cnt[i]]=x.st;
}
}
}
int main() {
scanf("%d %d",&n,&q);
for(int i=1;i<=n;i++) {
int x,y;
scanf("%d %d",&x,&y);
ar[i]={x,y};
}
sort(ar+1,ar+1+n,[](ii a,ii b){return a.st>b.st;});
cmp();
for(int i=1;i<=q;i++) {
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int bas=1,son=n;
while(bas<=son) {
if(ar[orta].st<=c-b) son=orta-1;
else bas=orta+1;
}
int ul=bas;
bas=1,son=n;
while(bas<=son) {
if(ar[orta].st<a) son=orta-1;
else bas=orta+1;
}
if(ul<=son) {
qu[ul-1].pb({1,c,i,-1});
qu[son].pb({1,c,i,1});
qu[ul-1].pb({0,b,i,1});
}
else {
qu[son].pb({0,b,i,1});
}
}
for(int i=1;i<=n;i++) {
s[0].up(1,1,cnt[0],fpos(0,ar[i].nd));
s[1].up(1,1,cnt[1],fpos(1,ar[i].st+ar[i].nd));
for(auto x:qu[i]) {
ans[x.id]+=x.sg*s[x.w].get(1,1,cnt[x.w],fpos(x.w,x.val),cnt[x.w]);
}
}
for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:98:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&q);
~~~~~^~~~~~~~~~~~~~~
examination.cpp:104:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x,&y);
~~~~~^~~~~~~~~~~~~~~
examination.cpp:118:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&a,&b,&c);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
10 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Correct |
16 ms |
7800 KB |
Output is correct |
8 |
Correct |
17 ms |
7800 KB |
Output is correct |
9 |
Correct |
16 ms |
7904 KB |
Output is correct |
10 |
Correct |
14 ms |
7672 KB |
Output is correct |
11 |
Correct |
15 ms |
7720 KB |
Output is correct |
12 |
Correct |
11 ms |
7544 KB |
Output is correct |
13 |
Correct |
16 ms |
7800 KB |
Output is correct |
14 |
Correct |
15 ms |
7800 KB |
Output is correct |
15 |
Correct |
15 ms |
7848 KB |
Output is correct |
16 |
Correct |
14 ms |
7672 KB |
Output is correct |
17 |
Correct |
16 ms |
7668 KB |
Output is correct |
18 |
Correct |
10 ms |
7544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
17716 KB |
Output is correct |
2 |
Correct |
334 ms |
20216 KB |
Output is correct |
3 |
Correct |
322 ms |
20292 KB |
Output is correct |
4 |
Correct |
160 ms |
14748 KB |
Output is correct |
5 |
Correct |
278 ms |
15676 KB |
Output is correct |
6 |
Correct |
84 ms |
12384 KB |
Output is correct |
7 |
Correct |
300 ms |
20088 KB |
Output is correct |
8 |
Correct |
329 ms |
20252 KB |
Output is correct |
9 |
Correct |
297 ms |
20088 KB |
Output is correct |
10 |
Correct |
260 ms |
15736 KB |
Output is correct |
11 |
Correct |
162 ms |
14584 KB |
Output is correct |
12 |
Correct |
65 ms |
12012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
17716 KB |
Output is correct |
2 |
Correct |
334 ms |
20216 KB |
Output is correct |
3 |
Correct |
322 ms |
20292 KB |
Output is correct |
4 |
Correct |
160 ms |
14748 KB |
Output is correct |
5 |
Correct |
278 ms |
15676 KB |
Output is correct |
6 |
Correct |
84 ms |
12384 KB |
Output is correct |
7 |
Correct |
300 ms |
20088 KB |
Output is correct |
8 |
Correct |
329 ms |
20252 KB |
Output is correct |
9 |
Correct |
297 ms |
20088 KB |
Output is correct |
10 |
Correct |
260 ms |
15736 KB |
Output is correct |
11 |
Correct |
162 ms |
14584 KB |
Output is correct |
12 |
Correct |
65 ms |
12012 KB |
Output is correct |
13 |
Correct |
481 ms |
20604 KB |
Output is correct |
14 |
Correct |
374 ms |
20676 KB |
Output is correct |
15 |
Correct |
336 ms |
20184 KB |
Output is correct |
16 |
Correct |
226 ms |
17016 KB |
Output is correct |
17 |
Correct |
272 ms |
16748 KB |
Output is correct |
18 |
Correct |
91 ms |
13140 KB |
Output is correct |
19 |
Correct |
378 ms |
21340 KB |
Output is correct |
20 |
Correct |
380 ms |
20584 KB |
Output is correct |
21 |
Correct |
410 ms |
21752 KB |
Output is correct |
22 |
Correct |
243 ms |
15604 KB |
Output is correct |
23 |
Correct |
161 ms |
14424 KB |
Output is correct |
24 |
Correct |
65 ms |
12104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
10 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Correct |
16 ms |
7800 KB |
Output is correct |
8 |
Correct |
17 ms |
7800 KB |
Output is correct |
9 |
Correct |
16 ms |
7904 KB |
Output is correct |
10 |
Correct |
14 ms |
7672 KB |
Output is correct |
11 |
Correct |
15 ms |
7720 KB |
Output is correct |
12 |
Correct |
11 ms |
7544 KB |
Output is correct |
13 |
Correct |
16 ms |
7800 KB |
Output is correct |
14 |
Correct |
15 ms |
7800 KB |
Output is correct |
15 |
Correct |
15 ms |
7848 KB |
Output is correct |
16 |
Correct |
14 ms |
7672 KB |
Output is correct |
17 |
Correct |
16 ms |
7668 KB |
Output is correct |
18 |
Correct |
10 ms |
7544 KB |
Output is correct |
19 |
Correct |
335 ms |
17716 KB |
Output is correct |
20 |
Correct |
334 ms |
20216 KB |
Output is correct |
21 |
Correct |
322 ms |
20292 KB |
Output is correct |
22 |
Correct |
160 ms |
14748 KB |
Output is correct |
23 |
Correct |
278 ms |
15676 KB |
Output is correct |
24 |
Correct |
84 ms |
12384 KB |
Output is correct |
25 |
Correct |
300 ms |
20088 KB |
Output is correct |
26 |
Correct |
329 ms |
20252 KB |
Output is correct |
27 |
Correct |
297 ms |
20088 KB |
Output is correct |
28 |
Correct |
260 ms |
15736 KB |
Output is correct |
29 |
Correct |
162 ms |
14584 KB |
Output is correct |
30 |
Correct |
65 ms |
12012 KB |
Output is correct |
31 |
Correct |
481 ms |
20604 KB |
Output is correct |
32 |
Correct |
374 ms |
20676 KB |
Output is correct |
33 |
Correct |
336 ms |
20184 KB |
Output is correct |
34 |
Correct |
226 ms |
17016 KB |
Output is correct |
35 |
Correct |
272 ms |
16748 KB |
Output is correct |
36 |
Correct |
91 ms |
13140 KB |
Output is correct |
37 |
Correct |
378 ms |
21340 KB |
Output is correct |
38 |
Correct |
380 ms |
20584 KB |
Output is correct |
39 |
Correct |
410 ms |
21752 KB |
Output is correct |
40 |
Correct |
243 ms |
15604 KB |
Output is correct |
41 |
Correct |
161 ms |
14424 KB |
Output is correct |
42 |
Correct |
65 ms |
12104 KB |
Output is correct |
43 |
Correct |
469 ms |
26440 KB |
Output is correct |
44 |
Correct |
461 ms |
26252 KB |
Output is correct |
45 |
Correct |
457 ms |
26360 KB |
Output is correct |
46 |
Correct |
275 ms |
18936 KB |
Output is correct |
47 |
Correct |
382 ms |
19800 KB |
Output is correct |
48 |
Correct |
91 ms |
16100 KB |
Output is correct |
49 |
Correct |
467 ms |
26380 KB |
Output is correct |
50 |
Correct |
462 ms |
26056 KB |
Output is correct |
51 |
Correct |
528 ms |
26024 KB |
Output is correct |
52 |
Correct |
338 ms |
19832 KB |
Output is correct |
53 |
Correct |
179 ms |
17656 KB |
Output is correct |