#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef ONPC
#include"debug.h"
#else
#define debug(...) 42
#endif
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 15;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int ans[MAXN];
template<class T> using order_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
struct point {
int x, y;
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<point> a(n);
vector<ll> b(n);
for (int i = 0; i < n; i++){
cin >> a[i].x >> a[i].y;
b[i] = a[i].x + a[i].y;
}
sort(all(b));
vector<array<int, 3>> queries(q);
vector<array<int, 3>> queriesA(q);
vector<array<int, 3>> queriesB(q);
for (int i = 0; i < q; i++){
cin >> queries[i][0] >> queries[i][1] >> queries[i][2];
queries[i][2] = max(queries[i][2], queries[i][0] + queries[i][1]);
queriesA[i] = {queries[i][2], queries[i][0], i};
queriesB[i] = {queries[i][2], queries[i][1], i};
ans[i] += lower_bound(all(b), queries[i][2]) - b.begin();
}
sort(all(queriesA), greater<>());
sort(all(queriesB), greater<>());
sort(all(a), [](point lh, point rh){
return lh.x + lh.y > rh.x + rh.y;
});
int p = 0;
order_set<pii> st;
for (int i = 0; i < q; i++){// solve for b
while (p < n && a[p].x + a[p].y >= queriesA[i][0]){
st.insert({a[p].x, p});
p++;
}
ans[queriesA[i][2]] += st.order_of_key({queriesA[i][1], -1});
}
st.clear();
p = 0;
for (int i = 0; i < q; i++){// solve for b
while (p < n && a[p].x + a[p].y >= queriesB[i][0]){
st.insert({a[p].y, p});
p++;
}
ans[queriesB[i][2]] += st.order_of_key({queriesB[i][1], -1});
}
for (int i = 0; i < q; i++){
cout << n - ans[i] << endl;
}
}
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
732 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
860 KB |
Output is correct |
14 |
Correct |
4 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
884 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
736 KB |
Output is correct |
18 |
Correct |
3 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
16212 KB |
Output is correct |
2 |
Correct |
179 ms |
16968 KB |
Output is correct |
3 |
Correct |
182 ms |
17032 KB |
Output is correct |
4 |
Correct |
136 ms |
16236 KB |
Output is correct |
5 |
Correct |
146 ms |
16244 KB |
Output is correct |
6 |
Correct |
125 ms |
15440 KB |
Output is correct |
7 |
Correct |
164 ms |
16828 KB |
Output is correct |
8 |
Correct |
166 ms |
16944 KB |
Output is correct |
9 |
Correct |
178 ms |
16848 KB |
Output is correct |
10 |
Correct |
162 ms |
16100 KB |
Output is correct |
11 |
Correct |
124 ms |
16088 KB |
Output is correct |
12 |
Correct |
131 ms |
15148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
16212 KB |
Output is correct |
2 |
Correct |
179 ms |
16968 KB |
Output is correct |
3 |
Correct |
182 ms |
17032 KB |
Output is correct |
4 |
Correct |
136 ms |
16236 KB |
Output is correct |
5 |
Correct |
146 ms |
16244 KB |
Output is correct |
6 |
Correct |
125 ms |
15440 KB |
Output is correct |
7 |
Correct |
164 ms |
16828 KB |
Output is correct |
8 |
Correct |
166 ms |
16944 KB |
Output is correct |
9 |
Correct |
178 ms |
16848 KB |
Output is correct |
10 |
Correct |
162 ms |
16100 KB |
Output is correct |
11 |
Correct |
124 ms |
16088 KB |
Output is correct |
12 |
Correct |
131 ms |
15148 KB |
Output is correct |
13 |
Correct |
164 ms |
17260 KB |
Output is correct |
14 |
Correct |
211 ms |
17232 KB |
Output is correct |
15 |
Correct |
170 ms |
17032 KB |
Output is correct |
16 |
Correct |
136 ms |
16588 KB |
Output is correct |
17 |
Correct |
138 ms |
16612 KB |
Output is correct |
18 |
Correct |
125 ms |
15508 KB |
Output is correct |
19 |
Correct |
180 ms |
17488 KB |
Output is correct |
20 |
Correct |
186 ms |
17356 KB |
Output is correct |
21 |
Correct |
179 ms |
17612 KB |
Output is correct |
22 |
Correct |
176 ms |
15952 KB |
Output is correct |
23 |
Correct |
123 ms |
16324 KB |
Output is correct |
24 |
Correct |
141 ms |
15184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
732 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
860 KB |
Output is correct |
14 |
Correct |
4 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
884 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
736 KB |
Output is correct |
18 |
Correct |
3 ms |
800 KB |
Output is correct |
19 |
Correct |
174 ms |
16212 KB |
Output is correct |
20 |
Correct |
179 ms |
16968 KB |
Output is correct |
21 |
Correct |
182 ms |
17032 KB |
Output is correct |
22 |
Correct |
136 ms |
16236 KB |
Output is correct |
23 |
Correct |
146 ms |
16244 KB |
Output is correct |
24 |
Correct |
125 ms |
15440 KB |
Output is correct |
25 |
Correct |
164 ms |
16828 KB |
Output is correct |
26 |
Correct |
166 ms |
16944 KB |
Output is correct |
27 |
Correct |
178 ms |
16848 KB |
Output is correct |
28 |
Correct |
162 ms |
16100 KB |
Output is correct |
29 |
Correct |
124 ms |
16088 KB |
Output is correct |
30 |
Correct |
131 ms |
15148 KB |
Output is correct |
31 |
Correct |
164 ms |
17260 KB |
Output is correct |
32 |
Correct |
211 ms |
17232 KB |
Output is correct |
33 |
Correct |
170 ms |
17032 KB |
Output is correct |
34 |
Correct |
136 ms |
16588 KB |
Output is correct |
35 |
Correct |
138 ms |
16612 KB |
Output is correct |
36 |
Correct |
125 ms |
15508 KB |
Output is correct |
37 |
Correct |
180 ms |
17488 KB |
Output is correct |
38 |
Correct |
186 ms |
17356 KB |
Output is correct |
39 |
Correct |
179 ms |
17612 KB |
Output is correct |
40 |
Correct |
176 ms |
15952 KB |
Output is correct |
41 |
Correct |
123 ms |
16324 KB |
Output is correct |
42 |
Correct |
141 ms |
15184 KB |
Output is correct |
43 |
Correct |
180 ms |
19396 KB |
Output is correct |
44 |
Correct |
183 ms |
19288 KB |
Output is correct |
45 |
Correct |
195 ms |
19280 KB |
Output is correct |
46 |
Correct |
167 ms |
17744 KB |
Output is correct |
47 |
Correct |
143 ms |
17760 KB |
Output is correct |
48 |
Correct |
115 ms |
15452 KB |
Output is correct |
49 |
Correct |
176 ms |
19180 KB |
Output is correct |
50 |
Correct |
188 ms |
19200 KB |
Output is correct |
51 |
Correct |
181 ms |
19032 KB |
Output is correct |
52 |
Correct |
171 ms |
17496 KB |
Output is correct |
53 |
Correct |
172 ms |
17236 KB |
Output is correct |