#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
int n,q,res[maxn];
struct stu{
int a,b,c;
bool operator <(const stu fake)const{
if(c==fake.c){
return a<fake.a;
}
return c<fake.c;
}
};
struct qu{
int a,b,c,ind;
bool operator <(const qu fake)const{
if(c==fake.c){
return a<fake.a;
}
return c<fake.c;
}
};
vector<stu>alls;
vector<qu>allq;
struct fenwick{
vector<int>fn;
int sz;
void create(int a){
sz=a+10;
fn.resize(sz);
}
void add(int i,int w){
i++;
while(i<sz){
fn[i]+=w;
i+=((-i)&i);
}
}
int pors(int i){
i++;
int ret=0;
while(i>0){
ret+=fn[i];
i-=((-i)&i);
}
return ret;
}
};
struct fenwicka{
struct node{
vector<int>v;
fenwick f;
};
node fen[maxn];
void ins(int i,int w){
i++;
while(i<maxn){
fen[i].v.push_back(w);
i+=((-i)&i);
}
}
void build(){
for(int i=0;i<maxn;i++){
sort(fen[i].v.begin(),fen[i].v.end());
fen[i].v.resize(unique(fen[i].v.begin(),fen[i].v.end())-fen[i].v.begin());
fen[i].f.create(fen[i].v.size());
}
}
void upd(int i,int w){
i++;
while(i<maxn){
int p=lower_bound(fen[i].v.begin(),fen[i].v.end(),w)-fen[i].v.begin();
fen[i].f.add(p,1);
i+=((-i)&i);
}
}
int pors(int i,int w){
i++;
int ret=0;
while(i>0){
int p=lower_bound(fen[i].v.begin(),fen[i].v.end(),w)-fen[i].v.begin();
ret+=fen[i].f.pors((int)fen[i].v.size()+2)-fen[i].f.pors(p-1);
i-=((-i)&i);
}
return ret;
}
}fen;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
alls.resize(n);
allq.resize(q);
vector<int>allind;
for(int i=0;i<n;i++){
cin>>alls[i].a>>alls[i].b;
alls[i].c=alls[i].a+alls[i].b;
allind.push_back(alls[i].a);
}
sort(allind.begin(),allind.end());
allind.resize(unique(allind.begin(),allind.end())-allind.begin());
for(int i=0;i<q;i++){
cin>>allq[i].a>>allq[i].b>>allq[i].c;
allq[i].ind=i;
}
sort(alls.begin(),alls.end());
sort(allq.begin(),allq.end());
for(auto x:alls){
int p=lower_bound(allind.begin(),allind.end(),x.a)-allind.begin();
fen.ins(p,x.b);
}
fen.build();
while((int)allq.size()>0){
while((int)alls.size()>0&&alls.back().c>=allq.back().c){
int p=lower_bound(allind.begin(),allind.end(),alls.back().a)-allind.begin();
fen.upd(p,alls.back().b);
alls.pop_back();
}
int p=lower_bound(allind.begin(),allind.end(),allq.back().a)-allind.begin();
res[allq.back().ind]=fen.pors(maxn-2,allq.back().b)-fen.pors(p-1,allq.back().b);
allq.pop_back();
}
for(int i=0;i<q;i++){
cout<<res[i]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10584 KB |
Output is correct |
2 |
Correct |
7 ms |
10584 KB |
Output is correct |
3 |
Correct |
8 ms |
10640 KB |
Output is correct |
4 |
Correct |
7 ms |
10588 KB |
Output is correct |
5 |
Correct |
7 ms |
10588 KB |
Output is correct |
6 |
Correct |
7 ms |
10588 KB |
Output is correct |
7 |
Correct |
15 ms |
11096 KB |
Output is correct |
8 |
Correct |
16 ms |
11100 KB |
Output is correct |
9 |
Correct |
16 ms |
11100 KB |
Output is correct |
10 |
Correct |
13 ms |
11016 KB |
Output is correct |
11 |
Correct |
13 ms |
11096 KB |
Output is correct |
12 |
Correct |
11 ms |
10844 KB |
Output is correct |
13 |
Correct |
15 ms |
11100 KB |
Output is correct |
14 |
Correct |
15 ms |
11072 KB |
Output is correct |
15 |
Correct |
15 ms |
11096 KB |
Output is correct |
16 |
Correct |
12 ms |
11100 KB |
Output is correct |
17 |
Correct |
11 ms |
11012 KB |
Output is correct |
18 |
Correct |
10 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
26320 KB |
Output is correct |
2 |
Correct |
297 ms |
26584 KB |
Output is correct |
3 |
Correct |
305 ms |
26368 KB |
Output is correct |
4 |
Correct |
142 ms |
23248 KB |
Output is correct |
5 |
Correct |
205 ms |
27856 KB |
Output is correct |
6 |
Correct |
93 ms |
22740 KB |
Output is correct |
7 |
Correct |
294 ms |
26476 KB |
Output is correct |
8 |
Correct |
281 ms |
26604 KB |
Output is correct |
9 |
Correct |
239 ms |
26328 KB |
Output is correct |
10 |
Correct |
161 ms |
28028 KB |
Output is correct |
11 |
Correct |
105 ms |
22736 KB |
Output is correct |
12 |
Correct |
83 ms |
22648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
26320 KB |
Output is correct |
2 |
Correct |
297 ms |
26584 KB |
Output is correct |
3 |
Correct |
305 ms |
26368 KB |
Output is correct |
4 |
Correct |
142 ms |
23248 KB |
Output is correct |
5 |
Correct |
205 ms |
27856 KB |
Output is correct |
6 |
Correct |
93 ms |
22740 KB |
Output is correct |
7 |
Correct |
294 ms |
26476 KB |
Output is correct |
8 |
Correct |
281 ms |
26604 KB |
Output is correct |
9 |
Correct |
239 ms |
26328 KB |
Output is correct |
10 |
Correct |
161 ms |
28028 KB |
Output is correct |
11 |
Correct |
105 ms |
22736 KB |
Output is correct |
12 |
Correct |
83 ms |
22648 KB |
Output is correct |
13 |
Correct |
358 ms |
26832 KB |
Output is correct |
14 |
Correct |
359 ms |
26900 KB |
Output is correct |
15 |
Correct |
293 ms |
26656 KB |
Output is correct |
16 |
Correct |
154 ms |
23512 KB |
Output is correct |
17 |
Correct |
213 ms |
28008 KB |
Output is correct |
18 |
Correct |
100 ms |
23064 KB |
Output is correct |
19 |
Correct |
380 ms |
26944 KB |
Output is correct |
20 |
Correct |
355 ms |
26944 KB |
Output is correct |
21 |
Correct |
344 ms |
26968 KB |
Output is correct |
22 |
Correct |
170 ms |
28276 KB |
Output is correct |
23 |
Correct |
103 ms |
22740 KB |
Output is correct |
24 |
Correct |
81 ms |
22648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10584 KB |
Output is correct |
2 |
Correct |
7 ms |
10584 KB |
Output is correct |
3 |
Correct |
8 ms |
10640 KB |
Output is correct |
4 |
Correct |
7 ms |
10588 KB |
Output is correct |
5 |
Correct |
7 ms |
10588 KB |
Output is correct |
6 |
Correct |
7 ms |
10588 KB |
Output is correct |
7 |
Correct |
15 ms |
11096 KB |
Output is correct |
8 |
Correct |
16 ms |
11100 KB |
Output is correct |
9 |
Correct |
16 ms |
11100 KB |
Output is correct |
10 |
Correct |
13 ms |
11016 KB |
Output is correct |
11 |
Correct |
13 ms |
11096 KB |
Output is correct |
12 |
Correct |
11 ms |
10844 KB |
Output is correct |
13 |
Correct |
15 ms |
11100 KB |
Output is correct |
14 |
Correct |
15 ms |
11072 KB |
Output is correct |
15 |
Correct |
15 ms |
11096 KB |
Output is correct |
16 |
Correct |
12 ms |
11100 KB |
Output is correct |
17 |
Correct |
11 ms |
11012 KB |
Output is correct |
18 |
Correct |
10 ms |
10844 KB |
Output is correct |
19 |
Correct |
292 ms |
26320 KB |
Output is correct |
20 |
Correct |
297 ms |
26584 KB |
Output is correct |
21 |
Correct |
305 ms |
26368 KB |
Output is correct |
22 |
Correct |
142 ms |
23248 KB |
Output is correct |
23 |
Correct |
205 ms |
27856 KB |
Output is correct |
24 |
Correct |
93 ms |
22740 KB |
Output is correct |
25 |
Correct |
294 ms |
26476 KB |
Output is correct |
26 |
Correct |
281 ms |
26604 KB |
Output is correct |
27 |
Correct |
239 ms |
26328 KB |
Output is correct |
28 |
Correct |
161 ms |
28028 KB |
Output is correct |
29 |
Correct |
105 ms |
22736 KB |
Output is correct |
30 |
Correct |
83 ms |
22648 KB |
Output is correct |
31 |
Correct |
358 ms |
26832 KB |
Output is correct |
32 |
Correct |
359 ms |
26900 KB |
Output is correct |
33 |
Correct |
293 ms |
26656 KB |
Output is correct |
34 |
Correct |
154 ms |
23512 KB |
Output is correct |
35 |
Correct |
213 ms |
28008 KB |
Output is correct |
36 |
Correct |
100 ms |
23064 KB |
Output is correct |
37 |
Correct |
380 ms |
26944 KB |
Output is correct |
38 |
Correct |
355 ms |
26944 KB |
Output is correct |
39 |
Correct |
344 ms |
26968 KB |
Output is correct |
40 |
Correct |
170 ms |
28276 KB |
Output is correct |
41 |
Correct |
103 ms |
22740 KB |
Output is correct |
42 |
Correct |
81 ms |
22648 KB |
Output is correct |
43 |
Correct |
401 ms |
29760 KB |
Output is correct |
44 |
Correct |
459 ms |
29652 KB |
Output is correct |
45 |
Correct |
427 ms |
29564 KB |
Output is correct |
46 |
Correct |
192 ms |
25680 KB |
Output is correct |
47 |
Correct |
221 ms |
31212 KB |
Output is correct |
48 |
Correct |
100 ms |
22856 KB |
Output is correct |
49 |
Correct |
340 ms |
29512 KB |
Output is correct |
50 |
Correct |
367 ms |
29344 KB |
Output is correct |
51 |
Correct |
307 ms |
29300 KB |
Output is correct |
52 |
Correct |
210 ms |
32104 KB |
Output is correct |
53 |
Correct |
117 ms |
24276 KB |
Output is correct |