#include<bits/stdc++.h>
using namespace std;
#define jizz ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ALL(x) (x).begin(),(x).end()
typedef pair<int,int> pii;
#define F first
#define S second
const int MAXN=1E5+10;
struct student{
int type, a, b, c, id;
student(int t, int a, int b, int c, int id):type(t),a(a),b(b),c(c),id(id){};
};
bool cmp(student x, student y){
if(x.c==y.c) return x.type<y.type;
return x.c>y.c;
}
int n, q, ans[MAXN];
vector<int> comp;
vector<student> v;
struct BIT{
int data[MAXN]={0};
vector<pii> his;
int lb(int x){
return x&(-x);
}
void modify(int p, int v, bool u=1){
if(u) his.push_back({p,v});
//if(u) cout<<"modified "<<p<<" "<<v<<"\n";
while(p<MAXN){
data[p]+=v;
p+=lb(p);
}
}
int query(int p){
int res=0;
while(p>0){
res+=data[p];
p-=lb(p);
}
return res;
}
int query(int l, int r){
//cout<<"queried "<<l<<" "<<r<<"\n";
int x=query(r)-query(l-1);
//cout<<"result: "<<x<<"\n";
return x;
}
void undo(){
for(auto i:his){
modify(i.F,-i.S,0);
}
his.clear();
}
} bit;
void CDQORZ(int l, int r){
if(l==r) return;
int mid=(l+r)/2;
CDQORZ(l,mid);
CDQORZ(mid+1,r);
vector<student> nv;
int i=l, j=mid+1;
//cout<<"now on "<<l<<" "<<r<<"\n";
while(i<=mid||j<=r){
//cout<<i<<" "<<j<<"\n";
if(j==r+1){
nv.push_back(v[i]);
if(v[i].type==0) bit.modify(v[i].b,1);
i++;
} else if(i==mid+1){
nv.push_back(v[j]);
if(v[j].type==1) ans[v[j].id]+=bit.query(v[j].b,MAXN-1);
j++;
} else if(v[i].a>=v[j].a){
nv.push_back(v[i]);
if(v[i].type==0) bit.modify(v[i].b,1);
i++;
} else{
nv.push_back(v[j]);
if(v[j].type==1) ans[v[j].id]+=bit.query(v[j].b,MAXN-1);
j++;
}
}
bit.undo();
for(int k=0;k<nv.size();k++){
v[l+k]=nv[k];
}
}
int main(){ jizz
cin>>n>>q;
for(int i=0;i<n;i++){
int s, t;
cin>>s>>t;
v.push_back(student(0,s,t,s+t,i));
comp.push_back(t);
}
for(int i=0;i<q;i++){
int x, y, z;
cin>>x>>y>>z;
v.push_back(student(1,x,y,z,i));
comp.push_back(y);
}
sort(ALL(comp));
comp.erase(unique(ALL(comp)),comp.end());
for(int i=0;i<n+q;i++){
v[i].b=lower_bound(ALL(comp),v[i].b)-comp.begin()+1;
}
sort(ALL(v),cmp);
/*for(int i=0;i<n+q;i++){
cout<<v[i].type<<" "<<v[i].a<<" "<<v[i].b<<" "<<v[i].c<<" "<<v[i].id<<"\n";
}*/
CDQORZ(0,n+q-1);
for(int i=0;i<q;i++){
cout<<ans[i]<<"\n";
}
return 0;
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
*/
/*
10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117
*/
Compilation message
examination.cpp: In function 'void CDQORZ(int, int)':
examination.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int k=0;k<nv.size();k++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
748 KB |
Output is correct |
3 |
Correct |
1 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
1 ms |
748 KB |
Output is correct |
6 |
Correct |
1 ms |
748 KB |
Output is correct |
7 |
Correct |
8 ms |
1360 KB |
Output is correct |
8 |
Correct |
9 ms |
1360 KB |
Output is correct |
9 |
Correct |
8 ms |
1360 KB |
Output is correct |
10 |
Correct |
7 ms |
1252 KB |
Output is correct |
11 |
Correct |
8 ms |
1252 KB |
Output is correct |
12 |
Correct |
6 ms |
1252 KB |
Output is correct |
13 |
Correct |
8 ms |
1380 KB |
Output is correct |
14 |
Correct |
8 ms |
1360 KB |
Output is correct |
15 |
Correct |
8 ms |
1360 KB |
Output is correct |
16 |
Correct |
7 ms |
1380 KB |
Output is correct |
17 |
Correct |
7 ms |
1252 KB |
Output is correct |
18 |
Correct |
6 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
17652 KB |
Output is correct |
2 |
Correct |
267 ms |
18164 KB |
Output is correct |
3 |
Correct |
264 ms |
18036 KB |
Output is correct |
4 |
Correct |
232 ms |
17268 KB |
Output is correct |
5 |
Correct |
248 ms |
17524 KB |
Output is correct |
6 |
Correct |
208 ms |
16628 KB |
Output is correct |
7 |
Correct |
263 ms |
17908 KB |
Output is correct |
8 |
Correct |
257 ms |
17908 KB |
Output is correct |
9 |
Correct |
254 ms |
17908 KB |
Output is correct |
10 |
Correct |
235 ms |
17424 KB |
Output is correct |
11 |
Correct |
217 ms |
17268 KB |
Output is correct |
12 |
Correct |
201 ms |
16628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
17652 KB |
Output is correct |
2 |
Correct |
267 ms |
18164 KB |
Output is correct |
3 |
Correct |
264 ms |
18036 KB |
Output is correct |
4 |
Correct |
232 ms |
17268 KB |
Output is correct |
5 |
Correct |
248 ms |
17524 KB |
Output is correct |
6 |
Correct |
208 ms |
16628 KB |
Output is correct |
7 |
Correct |
263 ms |
17908 KB |
Output is correct |
8 |
Correct |
257 ms |
17908 KB |
Output is correct |
9 |
Correct |
254 ms |
17908 KB |
Output is correct |
10 |
Correct |
235 ms |
17424 KB |
Output is correct |
11 |
Correct |
217 ms |
17268 KB |
Output is correct |
12 |
Correct |
201 ms |
16628 KB |
Output is correct |
13 |
Correct |
289 ms |
18036 KB |
Output is correct |
14 |
Correct |
295 ms |
17140 KB |
Output is correct |
15 |
Correct |
264 ms |
17140 KB |
Output is correct |
16 |
Correct |
253 ms |
16756 KB |
Output is correct |
17 |
Correct |
279 ms |
17012 KB |
Output is correct |
18 |
Correct |
212 ms |
16628 KB |
Output is correct |
19 |
Correct |
293 ms |
17012 KB |
Output is correct |
20 |
Correct |
298 ms |
17012 KB |
Output is correct |
21 |
Correct |
288 ms |
16964 KB |
Output is correct |
22 |
Correct |
239 ms |
17268 KB |
Output is correct |
23 |
Correct |
219 ms |
17396 KB |
Output is correct |
24 |
Correct |
198 ms |
16500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
748 KB |
Output is correct |
3 |
Correct |
1 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
1 ms |
748 KB |
Output is correct |
6 |
Correct |
1 ms |
748 KB |
Output is correct |
7 |
Correct |
8 ms |
1360 KB |
Output is correct |
8 |
Correct |
9 ms |
1360 KB |
Output is correct |
9 |
Correct |
8 ms |
1360 KB |
Output is correct |
10 |
Correct |
7 ms |
1252 KB |
Output is correct |
11 |
Correct |
8 ms |
1252 KB |
Output is correct |
12 |
Correct |
6 ms |
1252 KB |
Output is correct |
13 |
Correct |
8 ms |
1380 KB |
Output is correct |
14 |
Correct |
8 ms |
1360 KB |
Output is correct |
15 |
Correct |
8 ms |
1360 KB |
Output is correct |
16 |
Correct |
7 ms |
1380 KB |
Output is correct |
17 |
Correct |
7 ms |
1252 KB |
Output is correct |
18 |
Correct |
6 ms |
1248 KB |
Output is correct |
19 |
Correct |
266 ms |
17652 KB |
Output is correct |
20 |
Correct |
267 ms |
18164 KB |
Output is correct |
21 |
Correct |
264 ms |
18036 KB |
Output is correct |
22 |
Correct |
232 ms |
17268 KB |
Output is correct |
23 |
Correct |
248 ms |
17524 KB |
Output is correct |
24 |
Correct |
208 ms |
16628 KB |
Output is correct |
25 |
Correct |
263 ms |
17908 KB |
Output is correct |
26 |
Correct |
257 ms |
17908 KB |
Output is correct |
27 |
Correct |
254 ms |
17908 KB |
Output is correct |
28 |
Correct |
235 ms |
17424 KB |
Output is correct |
29 |
Correct |
217 ms |
17268 KB |
Output is correct |
30 |
Correct |
201 ms |
16628 KB |
Output is correct |
31 |
Correct |
289 ms |
18036 KB |
Output is correct |
32 |
Correct |
295 ms |
17140 KB |
Output is correct |
33 |
Correct |
264 ms |
17140 KB |
Output is correct |
34 |
Correct |
253 ms |
16756 KB |
Output is correct |
35 |
Correct |
279 ms |
17012 KB |
Output is correct |
36 |
Correct |
212 ms |
16628 KB |
Output is correct |
37 |
Correct |
293 ms |
17012 KB |
Output is correct |
38 |
Correct |
298 ms |
17012 KB |
Output is correct |
39 |
Correct |
288 ms |
16964 KB |
Output is correct |
40 |
Correct |
239 ms |
17268 KB |
Output is correct |
41 |
Correct |
219 ms |
17396 KB |
Output is correct |
42 |
Correct |
198 ms |
16500 KB |
Output is correct |
43 |
Incorrect |
288 ms |
16372 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |