#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
#define fi first
#define se second
int n,q;
pair <int,int> a[100100];
struct qrr{
int x,y,z,id;
bool operator < (const qrr &p)const{
return z > p.z;
}
} qr[100100];
vector <int> nen_x,nen_y;
vector <int> BIT[200100];
vector <int> VAL[200100];
int ans[100100];
int f(vector <int> &b, int x){
return lower_bound(b.begin(),b.end(),x) - b.begin();
}
void AddQuery(int x,int y){
x = f(nen_x,x);
for (;x > 0;x -= (x & (-x))){
VAL[x].push_back(y);
}
}
void AddUpdate(int x,int y){
x = f(nen_x,x);
for (;x < nen_x.size();x += (x & (-x))){
VAL[x].push_back(y);
}
}
void update(int x,int y){
x = f(nen_x,x);
for (;x < nen_x.size();x += x & -x){
for (int j = f(VAL[x],y);j < VAL[x].size(); j += j & -j){
BIT[x][j] ++;
}
}
}
int query(int x,int y){
x = f(nen_x,x);
int res = 0;
for (;x > 0;x -= x & -x){
for (int j = f(VAL[x],y);j > 0;j -= j & -j){
res += BIT[x][j];
}
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>q;
for (int i = 1;i <= n;i ++){
cin>>a[i].fi>>a[i].se;
nen_x.push_back(a[i].fi);
}
for (int i = 1;i <= q;i ++){
cin>>qr[i].x>>qr[i].y>>qr[i].z;
nen_x.push_back(qr[i].x-1);
qr[i].id = i;
}
sort(qr+1,qr+1+q);
nen_x.push_back(-1);
nen_x.push_back(INF);
sort(nen_x.begin(),nen_x.end());
nen_x.resize(unique(nen_x.begin(),nen_x.end()) - nen_x.begin());
for (int i = 1;i <= n;i ++){
AddUpdate(a[i].fi,a[i].se);
}
for (int i = 1;i <= q;i ++){
AddQuery(qr[i].x-1,INF);
AddQuery(INF,qr[i].y-1);
AddQuery(qr[i].x-1,qr[i].y-1);
}
for (int i = 1;i < nen_x.size();i++){
VAL[i].push_back(-1);
sort(VAL[i].begin(),VAL[i].end());
VAL[i].resize(unique(VAL[i].begin(),VAL[i].end()) - VAL[i].begin());
BIT[i].resize(VAL[i].size());
}
/*for (auto x:nen_x){
cout<<x<<' ';
}
cout<<'\n';
cout<<'\n';
for (int i = 1;i < nen_x.size();i++){
for (auto x:VAL[i]){
cout<<x<<' ';
}
cout<<'\n';
}
cout<<'\n';
for (int i = 1;i < nen_x.size();i++){
for (auto x:BIT[i]){
cout<<x<<' ';
}
cout<<'\n';
}
cout<<'\n';*/
sort(a+1,a+1+n,[=](pair <int,int> a,pair <int,int> b){return a.first + a.second > b.first + b.second;});
int cur = 1;
for (int i = 1;i <= q;i ++){
while (cur <= n && a[cur].fi + a[cur].se >= qr[i].z){
//cout<<a[cur].fi<<' '<<a[cur].se<<' '<<qr[i].z<<'\n';
update(a[cur].fi,a[cur].se);
cur++;
}
ans[qr[i].id] = (cur - 1) - query(qr[i].x-1,INF) - query(INF,qr[i].y-1) + query(qr[i].x-1,qr[i].y-1);
}
for (int i = 1;i <= q;i++){
cout<<ans[i]<<'\n';
}
cout<<'\n';
return 0;
}
Compilation message
examination.cpp: In function 'void AddUpdate(int, int)':
examination.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (;x < nen_x.size();x += (x & (-x))){
| ~~^~~~~~~~~~~~~~
examination.cpp: In function 'void update(int, int)':
examination.cpp:35:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (;x < nen_x.size();x += x & -x){
| ~~^~~~~~~~~~~~~~
examination.cpp:36:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int j = f(VAL[x],y);j < VAL[x].size(); j += j & -j){
| ~~^~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (int i = 1;i < nen_x.size();i++){
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9656 KB |
Output is correct |
4 |
Correct |
5 ms |
9824 KB |
Output is correct |
5 |
Correct |
6 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
17 ms |
10780 KB |
Output is correct |
8 |
Correct |
20 ms |
10708 KB |
Output is correct |
9 |
Correct |
17 ms |
10676 KB |
Output is correct |
10 |
Correct |
12 ms |
10516 KB |
Output is correct |
11 |
Correct |
9 ms |
10004 KB |
Output is correct |
12 |
Correct |
7 ms |
9940 KB |
Output is correct |
13 |
Correct |
16 ms |
10760 KB |
Output is correct |
14 |
Correct |
16 ms |
10708 KB |
Output is correct |
15 |
Correct |
18 ms |
10772 KB |
Output is correct |
16 |
Correct |
7 ms |
9940 KB |
Output is correct |
17 |
Correct |
10 ms |
10496 KB |
Output is correct |
18 |
Correct |
6 ms |
9940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
740 ms |
41628 KB |
Output is correct |
2 |
Correct |
715 ms |
41044 KB |
Output is correct |
3 |
Correct |
742 ms |
41732 KB |
Output is correct |
4 |
Correct |
276 ms |
32948 KB |
Output is correct |
5 |
Correct |
168 ms |
18580 KB |
Output is correct |
6 |
Correct |
83 ms |
17608 KB |
Output is correct |
7 |
Correct |
528 ms |
38076 KB |
Output is correct |
8 |
Correct |
649 ms |
38660 KB |
Output is correct |
9 |
Correct |
521 ms |
36516 KB |
Output is correct |
10 |
Correct |
106 ms |
15812 KB |
Output is correct |
11 |
Correct |
245 ms |
33584 KB |
Output is correct |
12 |
Correct |
65 ms |
16708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
740 ms |
41628 KB |
Output is correct |
2 |
Correct |
715 ms |
41044 KB |
Output is correct |
3 |
Correct |
742 ms |
41732 KB |
Output is correct |
4 |
Correct |
276 ms |
32948 KB |
Output is correct |
5 |
Correct |
168 ms |
18580 KB |
Output is correct |
6 |
Correct |
83 ms |
17608 KB |
Output is correct |
7 |
Correct |
528 ms |
38076 KB |
Output is correct |
8 |
Correct |
649 ms |
38660 KB |
Output is correct |
9 |
Correct |
521 ms |
36516 KB |
Output is correct |
10 |
Correct |
106 ms |
15812 KB |
Output is correct |
11 |
Correct |
245 ms |
33584 KB |
Output is correct |
12 |
Correct |
65 ms |
16708 KB |
Output is correct |
13 |
Correct |
757 ms |
40392 KB |
Output is correct |
14 |
Correct |
702 ms |
40516 KB |
Output is correct |
15 |
Correct |
693 ms |
39596 KB |
Output is correct |
16 |
Correct |
323 ms |
33860 KB |
Output is correct |
17 |
Correct |
182 ms |
18624 KB |
Output is correct |
18 |
Correct |
81 ms |
17680 KB |
Output is correct |
19 |
Correct |
755 ms |
40996 KB |
Output is correct |
20 |
Correct |
726 ms |
39664 KB |
Output is correct |
21 |
Correct |
749 ms |
40664 KB |
Output is correct |
22 |
Correct |
107 ms |
15832 KB |
Output is correct |
23 |
Correct |
248 ms |
33208 KB |
Output is correct |
24 |
Correct |
59 ms |
16612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9656 KB |
Output is correct |
4 |
Correct |
5 ms |
9824 KB |
Output is correct |
5 |
Correct |
6 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
17 ms |
10780 KB |
Output is correct |
8 |
Correct |
20 ms |
10708 KB |
Output is correct |
9 |
Correct |
17 ms |
10676 KB |
Output is correct |
10 |
Correct |
12 ms |
10516 KB |
Output is correct |
11 |
Correct |
9 ms |
10004 KB |
Output is correct |
12 |
Correct |
7 ms |
9940 KB |
Output is correct |
13 |
Correct |
16 ms |
10760 KB |
Output is correct |
14 |
Correct |
16 ms |
10708 KB |
Output is correct |
15 |
Correct |
18 ms |
10772 KB |
Output is correct |
16 |
Correct |
7 ms |
9940 KB |
Output is correct |
17 |
Correct |
10 ms |
10496 KB |
Output is correct |
18 |
Correct |
6 ms |
9940 KB |
Output is correct |
19 |
Correct |
740 ms |
41628 KB |
Output is correct |
20 |
Correct |
715 ms |
41044 KB |
Output is correct |
21 |
Correct |
742 ms |
41732 KB |
Output is correct |
22 |
Correct |
276 ms |
32948 KB |
Output is correct |
23 |
Correct |
168 ms |
18580 KB |
Output is correct |
24 |
Correct |
83 ms |
17608 KB |
Output is correct |
25 |
Correct |
528 ms |
38076 KB |
Output is correct |
26 |
Correct |
649 ms |
38660 KB |
Output is correct |
27 |
Correct |
521 ms |
36516 KB |
Output is correct |
28 |
Correct |
106 ms |
15812 KB |
Output is correct |
29 |
Correct |
245 ms |
33584 KB |
Output is correct |
30 |
Correct |
65 ms |
16708 KB |
Output is correct |
31 |
Correct |
757 ms |
40392 KB |
Output is correct |
32 |
Correct |
702 ms |
40516 KB |
Output is correct |
33 |
Correct |
693 ms |
39596 KB |
Output is correct |
34 |
Correct |
323 ms |
33860 KB |
Output is correct |
35 |
Correct |
182 ms |
18624 KB |
Output is correct |
36 |
Correct |
81 ms |
17680 KB |
Output is correct |
37 |
Correct |
755 ms |
40996 KB |
Output is correct |
38 |
Correct |
726 ms |
39664 KB |
Output is correct |
39 |
Correct |
749 ms |
40664 KB |
Output is correct |
40 |
Correct |
107 ms |
15832 KB |
Output is correct |
41 |
Correct |
248 ms |
33208 KB |
Output is correct |
42 |
Correct |
59 ms |
16612 KB |
Output is correct |
43 |
Correct |
869 ms |
49552 KB |
Output is correct |
44 |
Correct |
902 ms |
50244 KB |
Output is correct |
45 |
Correct |
887 ms |
50332 KB |
Output is correct |
46 |
Correct |
388 ms |
41284 KB |
Output is correct |
47 |
Correct |
188 ms |
19388 KB |
Output is correct |
48 |
Correct |
82 ms |
17364 KB |
Output is correct |
49 |
Correct |
798 ms |
50296 KB |
Output is correct |
50 |
Correct |
879 ms |
49504 KB |
Output is correct |
51 |
Correct |
735 ms |
47688 KB |
Output is correct |
52 |
Correct |
126 ms |
16700 KB |
Output is correct |
53 |
Correct |
326 ms |
40676 KB |
Output is correct |