#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
const int N = 1e5 + 10;
namespace BIT2D {
vector<int> val[N];
vector<int> bit[N];
void init() {
for(int i = 1 ; i < N ; ++i) {
sort(all(val[i]));
val[i].resize(unique(all(val[i])) - val[i].begin());
bit[i].resize(sz(val[i]) + 5);
}
}
int upd(int x,int y) {
for(; x > 0 ; x -= x & -x) {
int p = upper_bound(all(val[x]),y) - val[x].begin();
for(; p > 0 ; p -= p & -p)
bit[x][p]++;
}
}
int get(int x,int y) {
int ans = 0;
for(; x < N ; x += x & -x) {
int p = lower_bound(all(val[x]),y) - val[x].begin() + 1;
for(; p < bit[x].size() ; p += p & -p)
ans += bit[x][p];
}
return ans;
}
};
typedef pair<int,int> ii;
vector<ii> Poi;
vector<int> Que;
int Math[N];
int Info[N];
int Sum[N];
int ans[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n; Poi.resize(n);
int q; cin >> q;
vector<int> row = {-1};
vector<int> col = {-1};
for(ii &p : Poi) {
cin >> p.X >> p.Y;
row.pb(p.X);
col.pb(p.Y);
}
sort(all(Poi),[&](const ii &a,const ii &b) {
return a.X + a.Y > b.X + b.Y;
});
sort(all(row)); row.erase(unique(all(row)),row.end());
sort(all(col)); col.erase(unique(all(col)),col.end());
for(ii &p : Poi) {
p.X = lower_bound(all(row),p.X) - row.begin();
p.Y = lower_bound(all(col),p.Y) - col.begin();
for(int i = p.X ; i > 0 ; i -= i & -i)
BIT2D::val[i].push_back(p.Y);
}
for(int i = 0 ; i < q ; ++i) {
int M; cin >> M; Math[i] = lower_bound(all(row),M) - row.begin();
int I; cin >> I; Info[i] = lower_bound(all(col),I) - col.begin();
cin >> Sum[i];
Que.pb(i);
}
sort(all(Que),[&](const int &a,const int &b) {
return Sum[a] > Sum[b];
});
BIT2D::init();
int ptr = 0;
for(int i : Que) {
for(; ptr < Poi.size() ; ++ptr) {
int x = Poi[ptr].X;
int y = Poi[ptr].Y;
if (row[x] + col[y] < Sum[i])
break;
BIT2D::upd(x,y);
}
ans[i] = BIT2D::get(Math[i],Info[i]);
}
for(int i = 0 ; i < q ; ++i)
cout << ans[i] << "\n";
}
Compilation message
examination.cpp: In function 'int BIT2D::upd(int, int)':
examination.cpp:30:5: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
examination.cpp: In function 'int BIT2D::get(int, int)':
examination.cpp:35:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; p < bit[x].size() ; p += p & -p)
~~^~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:96:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; ptr < Poi.size() ; ++ptr) {
~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
8184 KB |
Output is correct |
2 |
Correct |
14 ms |
8184 KB |
Output is correct |
3 |
Correct |
14 ms |
8184 KB |
Output is correct |
4 |
Correct |
14 ms |
8184 KB |
Output is correct |
5 |
Correct |
14 ms |
8148 KB |
Output is correct |
6 |
Correct |
14 ms |
8184 KB |
Output is correct |
7 |
Correct |
23 ms |
8744 KB |
Output is correct |
8 |
Correct |
22 ms |
8696 KB |
Output is correct |
9 |
Correct |
22 ms |
8696 KB |
Output is correct |
10 |
Correct |
20 ms |
8572 KB |
Output is correct |
11 |
Correct |
19 ms |
8572 KB |
Output is correct |
12 |
Correct |
17 ms |
8312 KB |
Output is correct |
13 |
Correct |
22 ms |
8668 KB |
Output is correct |
14 |
Correct |
22 ms |
8740 KB |
Output is correct |
15 |
Correct |
22 ms |
8696 KB |
Output is correct |
16 |
Correct |
19 ms |
8440 KB |
Output is correct |
17 |
Correct |
19 ms |
8572 KB |
Output is correct |
18 |
Correct |
17 ms |
8312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
472 ms |
23020 KB |
Output is correct |
2 |
Correct |
462 ms |
23020 KB |
Output is correct |
3 |
Correct |
463 ms |
22968 KB |
Output is correct |
4 |
Correct |
217 ms |
20212 KB |
Output is correct |
5 |
Correct |
191 ms |
15724 KB |
Output is correct |
6 |
Correct |
111 ms |
14252 KB |
Output is correct |
7 |
Correct |
451 ms |
23020 KB |
Output is correct |
8 |
Correct |
421 ms |
23008 KB |
Output is correct |
9 |
Correct |
438 ms |
23020 KB |
Output is correct |
10 |
Correct |
147 ms |
14616 KB |
Output is correct |
11 |
Correct |
170 ms |
18924 KB |
Output is correct |
12 |
Correct |
88 ms |
13264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
472 ms |
23020 KB |
Output is correct |
2 |
Correct |
462 ms |
23020 KB |
Output is correct |
3 |
Correct |
463 ms |
22968 KB |
Output is correct |
4 |
Correct |
217 ms |
20212 KB |
Output is correct |
5 |
Correct |
191 ms |
15724 KB |
Output is correct |
6 |
Correct |
111 ms |
14252 KB |
Output is correct |
7 |
Correct |
451 ms |
23020 KB |
Output is correct |
8 |
Correct |
421 ms |
23008 KB |
Output is correct |
9 |
Correct |
438 ms |
23020 KB |
Output is correct |
10 |
Correct |
147 ms |
14616 KB |
Output is correct |
11 |
Correct |
170 ms |
18924 KB |
Output is correct |
12 |
Correct |
88 ms |
13264 KB |
Output is correct |
13 |
Correct |
502 ms |
23428 KB |
Output is correct |
14 |
Correct |
524 ms |
23412 KB |
Output is correct |
15 |
Correct |
461 ms |
22984 KB |
Output is correct |
16 |
Correct |
237 ms |
20460 KB |
Output is correct |
17 |
Correct |
212 ms |
16044 KB |
Output is correct |
18 |
Correct |
116 ms |
14188 KB |
Output is correct |
19 |
Correct |
499 ms |
23464 KB |
Output is correct |
20 |
Correct |
507 ms |
23532 KB |
Output is correct |
21 |
Correct |
494 ms |
23404 KB |
Output is correct |
22 |
Correct |
147 ms |
14584 KB |
Output is correct |
23 |
Correct |
176 ms |
19052 KB |
Output is correct |
24 |
Correct |
88 ms |
13396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
8184 KB |
Output is correct |
2 |
Correct |
14 ms |
8184 KB |
Output is correct |
3 |
Correct |
14 ms |
8184 KB |
Output is correct |
4 |
Correct |
14 ms |
8184 KB |
Output is correct |
5 |
Correct |
14 ms |
8148 KB |
Output is correct |
6 |
Correct |
14 ms |
8184 KB |
Output is correct |
7 |
Correct |
23 ms |
8744 KB |
Output is correct |
8 |
Correct |
22 ms |
8696 KB |
Output is correct |
9 |
Correct |
22 ms |
8696 KB |
Output is correct |
10 |
Correct |
20 ms |
8572 KB |
Output is correct |
11 |
Correct |
19 ms |
8572 KB |
Output is correct |
12 |
Correct |
17 ms |
8312 KB |
Output is correct |
13 |
Correct |
22 ms |
8668 KB |
Output is correct |
14 |
Correct |
22 ms |
8740 KB |
Output is correct |
15 |
Correct |
22 ms |
8696 KB |
Output is correct |
16 |
Correct |
19 ms |
8440 KB |
Output is correct |
17 |
Correct |
19 ms |
8572 KB |
Output is correct |
18 |
Correct |
17 ms |
8312 KB |
Output is correct |
19 |
Correct |
472 ms |
23020 KB |
Output is correct |
20 |
Correct |
462 ms |
23020 KB |
Output is correct |
21 |
Correct |
463 ms |
22968 KB |
Output is correct |
22 |
Correct |
217 ms |
20212 KB |
Output is correct |
23 |
Correct |
191 ms |
15724 KB |
Output is correct |
24 |
Correct |
111 ms |
14252 KB |
Output is correct |
25 |
Correct |
451 ms |
23020 KB |
Output is correct |
26 |
Correct |
421 ms |
23008 KB |
Output is correct |
27 |
Correct |
438 ms |
23020 KB |
Output is correct |
28 |
Correct |
147 ms |
14616 KB |
Output is correct |
29 |
Correct |
170 ms |
18924 KB |
Output is correct |
30 |
Correct |
88 ms |
13264 KB |
Output is correct |
31 |
Correct |
502 ms |
23428 KB |
Output is correct |
32 |
Correct |
524 ms |
23412 KB |
Output is correct |
33 |
Correct |
461 ms |
22984 KB |
Output is correct |
34 |
Correct |
237 ms |
20460 KB |
Output is correct |
35 |
Correct |
212 ms |
16044 KB |
Output is correct |
36 |
Correct |
116 ms |
14188 KB |
Output is correct |
37 |
Correct |
499 ms |
23464 KB |
Output is correct |
38 |
Correct |
507 ms |
23532 KB |
Output is correct |
39 |
Correct |
494 ms |
23404 KB |
Output is correct |
40 |
Correct |
147 ms |
14584 KB |
Output is correct |
41 |
Correct |
176 ms |
19052 KB |
Output is correct |
42 |
Correct |
88 ms |
13396 KB |
Output is correct |
43 |
Correct |
548 ms |
26116 KB |
Output is correct |
44 |
Correct |
553 ms |
26016 KB |
Output is correct |
45 |
Correct |
536 ms |
26024 KB |
Output is correct |
46 |
Correct |
264 ms |
22124 KB |
Output is correct |
47 |
Correct |
225 ms |
17388 KB |
Output is correct |
48 |
Correct |
121 ms |
14068 KB |
Output is correct |
49 |
Correct |
553 ms |
25940 KB |
Output is correct |
50 |
Correct |
494 ms |
25892 KB |
Output is correct |
51 |
Correct |
474 ms |
25864 KB |
Output is correct |
52 |
Correct |
179 ms |
16208 KB |
Output is correct |
53 |
Correct |
189 ms |
20332 KB |
Output is correct |