#include <bits/stdc++.h>
using namespace std;
#define int long long
pair<int, int> arr[100001];
bool cmp(pair<int, int> a, pair<int, int> b) {
return a.first + a.second < b.first + b.second;
}
struct node {
int s, e, m;
vector<int> v;
vector<int> v2;
node *l, *r;
node(int S, int E) {
s = S;
e = E;
m = (s + e) / 2;
if (s != e) {
l = new node(s, m);
r = new node(m + 1, e);
}
}
void update(int X, int V, int V2) {
v.push_back(V);
v2.push_back(V2);
if (X == e) {
sort(v.begin(), v.end());
sort(v2.begin(), v2.end());
}
if (s != e) {
if (X <= m) {
l -> update(X, V, V2);
} else {
r -> update(X, V, V2);
}
}
}
int query(int S, int E, int X, int Y) {
if (s == S && e == E) {
int a = lower_bound(v.begin(), v.end(), X) - v.begin();
int b = lower_bound(v2.begin(), v2.end(), Y) - v2.begin();
return a + b;
} else {
if (E <= m) {
return l -> query(S, E, X, Y);
} else if (S > m) {
return r -> query(S, E, X, Y);
} else {
return l -> query(S, m, X, Y) + r -> query(m + 1, E, X, Y);
}
}
}
} *root;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q;
cin >> n >> q;
root = new node(0, n - 1);
for (int i = 0; i < n; i++) {
cin >> arr[i].first >> arr[i].second;
}
sort(arr, arr + n, cmp);
for (int i = 0; i < n; i++) {
root -> update(i, arr[i].first, arr[i].second);
}
while (q--) {
int a, b, c;
cin >> a >> b >> c;
c = max(c, a + b);
int low = -1;
int high = n - 1;
while (high - low > 1) {
int mid = (high + low) / 2;
if (arr[mid].first + arr[mid].second < c) {
low = mid;
} else {
high = mid;
}
}
if (arr[high].first + arr[high].second < c) {
cout << 0 << '\n';
continue;
}
int ans = n - high;
cout << ans - root -> query(high, n - 1, a, b) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2136 KB |
Output is correct |
9 |
Correct |
8 ms |
2236 KB |
Output is correct |
10 |
Correct |
5 ms |
2136 KB |
Output is correct |
11 |
Correct |
6 ms |
2136 KB |
Output is correct |
12 |
Correct |
5 ms |
1884 KB |
Output is correct |
13 |
Correct |
7 ms |
2140 KB |
Output is correct |
14 |
Correct |
7 ms |
2136 KB |
Output is correct |
15 |
Correct |
7 ms |
2140 KB |
Output is correct |
16 |
Correct |
5 ms |
1980 KB |
Output is correct |
17 |
Correct |
5 ms |
2136 KB |
Output is correct |
18 |
Correct |
3 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
468 ms |
65064 KB |
Output is correct |
2 |
Correct |
473 ms |
64972 KB |
Output is correct |
3 |
Correct |
524 ms |
65008 KB |
Output is correct |
4 |
Correct |
334 ms |
64296 KB |
Output is correct |
5 |
Correct |
364 ms |
64844 KB |
Output is correct |
6 |
Correct |
198 ms |
63520 KB |
Output is correct |
7 |
Correct |
413 ms |
65324 KB |
Output is correct |
8 |
Correct |
403 ms |
64904 KB |
Output is correct |
9 |
Correct |
369 ms |
65064 KB |
Output is correct |
10 |
Correct |
281 ms |
64164 KB |
Output is correct |
11 |
Correct |
262 ms |
64148 KB |
Output is correct |
12 |
Correct |
113 ms |
63272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
468 ms |
65064 KB |
Output is correct |
2 |
Correct |
473 ms |
64972 KB |
Output is correct |
3 |
Correct |
524 ms |
65008 KB |
Output is correct |
4 |
Correct |
334 ms |
64296 KB |
Output is correct |
5 |
Correct |
364 ms |
64844 KB |
Output is correct |
6 |
Correct |
198 ms |
63520 KB |
Output is correct |
7 |
Correct |
413 ms |
65324 KB |
Output is correct |
8 |
Correct |
403 ms |
64904 KB |
Output is correct |
9 |
Correct |
369 ms |
65064 KB |
Output is correct |
10 |
Correct |
281 ms |
64164 KB |
Output is correct |
11 |
Correct |
262 ms |
64148 KB |
Output is correct |
12 |
Correct |
113 ms |
63272 KB |
Output is correct |
13 |
Correct |
421 ms |
65564 KB |
Output is correct |
14 |
Correct |
488 ms |
65316 KB |
Output is correct |
15 |
Correct |
519 ms |
65108 KB |
Output is correct |
16 |
Correct |
311 ms |
64632 KB |
Output is correct |
17 |
Correct |
326 ms |
64672 KB |
Output is correct |
18 |
Correct |
233 ms |
63528 KB |
Output is correct |
19 |
Correct |
426 ms |
65364 KB |
Output is correct |
20 |
Correct |
452 ms |
65444 KB |
Output is correct |
21 |
Correct |
423 ms |
65532 KB |
Output is correct |
22 |
Correct |
262 ms |
64296 KB |
Output is correct |
23 |
Correct |
265 ms |
64068 KB |
Output is correct |
24 |
Correct |
111 ms |
63160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
2140 KB |
Output is correct |
8 |
Correct |
7 ms |
2136 KB |
Output is correct |
9 |
Correct |
8 ms |
2236 KB |
Output is correct |
10 |
Correct |
5 ms |
2136 KB |
Output is correct |
11 |
Correct |
6 ms |
2136 KB |
Output is correct |
12 |
Correct |
5 ms |
1884 KB |
Output is correct |
13 |
Correct |
7 ms |
2140 KB |
Output is correct |
14 |
Correct |
7 ms |
2136 KB |
Output is correct |
15 |
Correct |
7 ms |
2140 KB |
Output is correct |
16 |
Correct |
5 ms |
1980 KB |
Output is correct |
17 |
Correct |
5 ms |
2136 KB |
Output is correct |
18 |
Correct |
3 ms |
1884 KB |
Output is correct |
19 |
Correct |
468 ms |
65064 KB |
Output is correct |
20 |
Correct |
473 ms |
64972 KB |
Output is correct |
21 |
Correct |
524 ms |
65008 KB |
Output is correct |
22 |
Correct |
334 ms |
64296 KB |
Output is correct |
23 |
Correct |
364 ms |
64844 KB |
Output is correct |
24 |
Correct |
198 ms |
63520 KB |
Output is correct |
25 |
Correct |
413 ms |
65324 KB |
Output is correct |
26 |
Correct |
403 ms |
64904 KB |
Output is correct |
27 |
Correct |
369 ms |
65064 KB |
Output is correct |
28 |
Correct |
281 ms |
64164 KB |
Output is correct |
29 |
Correct |
262 ms |
64148 KB |
Output is correct |
30 |
Correct |
113 ms |
63272 KB |
Output is correct |
31 |
Correct |
421 ms |
65564 KB |
Output is correct |
32 |
Correct |
488 ms |
65316 KB |
Output is correct |
33 |
Correct |
519 ms |
65108 KB |
Output is correct |
34 |
Correct |
311 ms |
64632 KB |
Output is correct |
35 |
Correct |
326 ms |
64672 KB |
Output is correct |
36 |
Correct |
233 ms |
63528 KB |
Output is correct |
37 |
Correct |
426 ms |
65364 KB |
Output is correct |
38 |
Correct |
452 ms |
65444 KB |
Output is correct |
39 |
Correct |
423 ms |
65532 KB |
Output is correct |
40 |
Correct |
262 ms |
64296 KB |
Output is correct |
41 |
Correct |
265 ms |
64068 KB |
Output is correct |
42 |
Correct |
111 ms |
63160 KB |
Output is correct |
43 |
Correct |
448 ms |
67876 KB |
Output is correct |
44 |
Correct |
480 ms |
67504 KB |
Output is correct |
45 |
Correct |
466 ms |
67368 KB |
Output is correct |
46 |
Correct |
335 ms |
65784 KB |
Output is correct |
47 |
Correct |
309 ms |
65816 KB |
Output is correct |
48 |
Correct |
179 ms |
63448 KB |
Output is correct |
49 |
Correct |
416 ms |
67372 KB |
Output is correct |
50 |
Correct |
446 ms |
67388 KB |
Output is correct |
51 |
Correct |
386 ms |
67184 KB |
Output is correct |
52 |
Correct |
256 ms |
65928 KB |
Output is correct |
53 |
Correct |
271 ms |
64808 KB |
Output is correct |