#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
struct cube{
int a,b,c,idx;
};
const int MAXN=1e5;
int ans[MAXN]={0};
int bit[2*MAXN+1]={0};
void update(int i,int x){
for(;i<=2*MAXN;i+=(i&(-i))){
bit[i]+=x;
}
}
int pre(int i){
int curr=0;
for(;i;i-=(i&(-i))){
curr+=bit[i];
}
return curr;
}
int query(int l,int r){
return pre(r)-pre(l-1);
}
bool cmp(cube &a,cube &b){
return (a.b>b.b);
}
bool cmp2(cube &a,cube &b){
if(a.a!=b.a){
return (a.a<b.a);
}
if(a.idx!=b.idx){
return (a.idx>b.idx);
}
}
void dnc(vector<cube> &v){
if(v.size()<=1){
return;
}
int mid=(v.size()>>1);
vector<cube> v1,v2;
for(int i=0;i<mid;i++){
v1.push_back(v[i]);
}
for(int i=mid;i<v.size();i++){
v2.push_back(v[i]);
}
dnc(v1),dnc(v2);
sort(v.begin(),v.end(),cmp);
/*cout << "GOT" << endl;
cout << "V1: " << endl;
for(int i=0;i<v1.size();i++){
cout << v1[i].a << ' ' << v1[i].b << ' ' << v1[i].c << ' ' << v1[i].idx << endl;
}
cout << "V2: " << endl;
for(int i=0;i<v2.size();i++){
cout << v2[i].a << ' ' << v2[i].b << ' ' << v2[i].c << ' ' << v2[i].idx << endl;
}*/
int ptr=0;
for(int i=0;i<v2.size();i++){
while(ptr<v1.size()&&v1[ptr].b>v2[i].b){
if(v1[ptr].idx!=-1){
ans[v1[ptr].idx]+=query(v1[ptr].c,2*MAXN);
}
ptr++;
}
if(v2[i].idx==-1){
update(v2[i].c,1);
}
}
while(ptr<v1.size()){
if(v1[ptr].idx!=-1){
ans[v1[ptr].idx]+=query(v1[ptr].c,2*MAXN);
}
ptr++;
}
for(int i=0;i<v2.size();i++){
if(v2[i].idx==-1){
update(v2[i].c,-1);
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,q;
cin >> n >> q;
vector<cube> v;
map<int,int> mp;
for(int i=0;i<n;i++){
int s,t;
cin >> s >> t;
v.push_back({s,t,s+t,-1});
mp[s+t]=1;
}
for(int i=0;i<q;i++){
int x,y,z;
cin >> x >> y >> z;
v.push_back({x,y,z,i});
mp[z]=1;
}
int idx=1;
for(pair<const int,int> &x:mp){
x.second=idx;
idx++;
}
for(int i=0;i<v.size();i++){
v[i].c=mp[v[i].c];
}
for(int i=0;i<v.size();i++){
// cout << v[i].a << ' ' << v[i].b << ' ' << v[i].c << ' ' << v[i].idx << endl;
}
sort(v.begin(),v.end(),cmp2);
dnc(v);
for(int i=0;i<q;i++){
cout << ans[i] << endl;
}
}
Compilation message
examination.cpp: In function 'void dnc(std::vector<cube>&)':
examination.cpp:46:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=mid;i<v.size();i++){
| ~^~~~~~~~~
examination.cpp:61:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0;i<v2.size();i++){
| ~^~~~~~~~~~
examination.cpp:62:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | while(ptr<v1.size()&&v1[ptr].b>v2[i].b){
| ~~~^~~~~~~~~~
examination.cpp:72:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while(ptr<v1.size()){
| ~~~^~~~~~~~~~
examination.cpp:78:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i=0;i<v2.size();i++){
| ~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:108:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
examination.cpp:111:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
examination.cpp: In function 'bool cmp2(cube&, cube&)':
examination.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
36 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
10 ms |
1496 KB |
Output is correct |
8 |
Correct |
10 ms |
1492 KB |
Output is correct |
9 |
Correct |
10 ms |
1492 KB |
Output is correct |
10 |
Correct |
9 ms |
1496 KB |
Output is correct |
11 |
Correct |
10 ms |
1496 KB |
Output is correct |
12 |
Correct |
7 ms |
988 KB |
Output is correct |
13 |
Correct |
9 ms |
3368 KB |
Output is correct |
14 |
Correct |
9 ms |
3288 KB |
Output is correct |
15 |
Correct |
9 ms |
3352 KB |
Output is correct |
16 |
Correct |
9 ms |
1236 KB |
Output is correct |
17 |
Correct |
7 ms |
3544 KB |
Output is correct |
18 |
Correct |
5 ms |
988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
417 ms |
29868 KB |
Output is correct |
2 |
Correct |
420 ms |
28844 KB |
Output is correct |
3 |
Correct |
423 ms |
28604 KB |
Output is correct |
4 |
Correct |
327 ms |
29356 KB |
Output is correct |
5 |
Correct |
397 ms |
29328 KB |
Output is correct |
6 |
Correct |
261 ms |
21664 KB |
Output is correct |
7 |
Correct |
398 ms |
29216 KB |
Output is correct |
8 |
Correct |
417 ms |
28332 KB |
Output is correct |
9 |
Correct |
397 ms |
28076 KB |
Output is correct |
10 |
Correct |
381 ms |
26540 KB |
Output is correct |
11 |
Correct |
264 ms |
28844 KB |
Output is correct |
12 |
Correct |
248 ms |
22708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
417 ms |
29868 KB |
Output is correct |
2 |
Correct |
420 ms |
28844 KB |
Output is correct |
3 |
Correct |
423 ms |
28604 KB |
Output is correct |
4 |
Correct |
327 ms |
29356 KB |
Output is correct |
5 |
Correct |
397 ms |
29328 KB |
Output is correct |
6 |
Correct |
261 ms |
21664 KB |
Output is correct |
7 |
Correct |
398 ms |
29216 KB |
Output is correct |
8 |
Correct |
417 ms |
28332 KB |
Output is correct |
9 |
Correct |
397 ms |
28076 KB |
Output is correct |
10 |
Correct |
381 ms |
26540 KB |
Output is correct |
11 |
Correct |
264 ms |
28844 KB |
Output is correct |
12 |
Correct |
248 ms |
22708 KB |
Output is correct |
13 |
Correct |
488 ms |
30384 KB |
Output is correct |
14 |
Correct |
486 ms |
30640 KB |
Output is correct |
15 |
Correct |
417 ms |
28368 KB |
Output is correct |
16 |
Correct |
384 ms |
28076 KB |
Output is correct |
17 |
Correct |
428 ms |
27564 KB |
Output is correct |
18 |
Correct |
263 ms |
22452 KB |
Output is correct |
19 |
Correct |
475 ms |
32172 KB |
Output is correct |
20 |
Correct |
474 ms |
32944 KB |
Output is correct |
21 |
Correct |
468 ms |
31920 KB |
Output is correct |
22 |
Correct |
393 ms |
25772 KB |
Output is correct |
23 |
Correct |
273 ms |
27516 KB |
Output is correct |
24 |
Correct |
223 ms |
21540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
10 ms |
1496 KB |
Output is correct |
8 |
Correct |
10 ms |
1492 KB |
Output is correct |
9 |
Correct |
10 ms |
1492 KB |
Output is correct |
10 |
Correct |
9 ms |
1496 KB |
Output is correct |
11 |
Correct |
10 ms |
1496 KB |
Output is correct |
12 |
Correct |
7 ms |
988 KB |
Output is correct |
13 |
Correct |
9 ms |
3368 KB |
Output is correct |
14 |
Correct |
9 ms |
3288 KB |
Output is correct |
15 |
Correct |
9 ms |
3352 KB |
Output is correct |
16 |
Correct |
9 ms |
1236 KB |
Output is correct |
17 |
Correct |
7 ms |
3544 KB |
Output is correct |
18 |
Correct |
5 ms |
988 KB |
Output is correct |
19 |
Correct |
417 ms |
29868 KB |
Output is correct |
20 |
Correct |
420 ms |
28844 KB |
Output is correct |
21 |
Correct |
423 ms |
28604 KB |
Output is correct |
22 |
Correct |
327 ms |
29356 KB |
Output is correct |
23 |
Correct |
397 ms |
29328 KB |
Output is correct |
24 |
Correct |
261 ms |
21664 KB |
Output is correct |
25 |
Correct |
398 ms |
29216 KB |
Output is correct |
26 |
Correct |
417 ms |
28332 KB |
Output is correct |
27 |
Correct |
397 ms |
28076 KB |
Output is correct |
28 |
Correct |
381 ms |
26540 KB |
Output is correct |
29 |
Correct |
264 ms |
28844 KB |
Output is correct |
30 |
Correct |
248 ms |
22708 KB |
Output is correct |
31 |
Correct |
488 ms |
30384 KB |
Output is correct |
32 |
Correct |
486 ms |
30640 KB |
Output is correct |
33 |
Correct |
417 ms |
28368 KB |
Output is correct |
34 |
Correct |
384 ms |
28076 KB |
Output is correct |
35 |
Correct |
428 ms |
27564 KB |
Output is correct |
36 |
Correct |
263 ms |
22452 KB |
Output is correct |
37 |
Correct |
475 ms |
32172 KB |
Output is correct |
38 |
Correct |
474 ms |
32944 KB |
Output is correct |
39 |
Correct |
468 ms |
31920 KB |
Output is correct |
40 |
Correct |
393 ms |
25772 KB |
Output is correct |
41 |
Correct |
273 ms |
27516 KB |
Output is correct |
42 |
Correct |
223 ms |
21540 KB |
Output is correct |
43 |
Correct |
530 ms |
36212 KB |
Output is correct |
44 |
Correct |
520 ms |
36780 KB |
Output is correct |
45 |
Correct |
518 ms |
37292 KB |
Output is correct |
46 |
Correct |
429 ms |
37036 KB |
Output is correct |
47 |
Correct |
503 ms |
37296 KB |
Output is correct |
48 |
Correct |
268 ms |
21688 KB |
Output is correct |
49 |
Correct |
530 ms |
38316 KB |
Output is correct |
50 |
Correct |
507 ms |
36904 KB |
Output is correct |
51 |
Correct |
505 ms |
37548 KB |
Output is correct |
52 |
Correct |
482 ms |
36368 KB |
Output is correct |
53 |
Correct |
274 ms |
29868 KB |
Output is correct |